OpenKinect c++ - Freenect::Freenect Freenect

发布于 2024-12-10 08:41:48 字数 2394 浏览 1 评论 0原文

我对 OpenKinect 提供的代码有疑问。我尝试将 Kinect 与 C++ 结合使用,但出现此错误。在网上已经有人问过这个问题,但我还没有找到合适的答案。代码是这样的:

#include <cstdlib>
#include "libfreenect.h"
#include "libfreenect.hpp"
#include <pthread.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cmath>
#include <vector>
#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif

using namespace std;

class Mutex {
    ...
};

class MyFreenectDevice : public Freenect::FreenectDevice {
    public:
    MyFreenectDevice(freenect_context *_ctx, int _index)
    : Freenect::FreenectDevice(_ctx, _index),
               m_buffer_depth(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
               m_buffer_video(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
               m_gamma(2048),
               m_new_rgb_frame(false),
               m_new_depth_frame(false)
    {
        for (unsigned int i = 0; i < 2048; i++) {
            float v = i / 2048.0;
            v = std::pow(v, 3) * 6;
            m_gamma[i] = v * 6 * 256;
        }
    }
    ...

    private:
    std::vector<uint8_t> m_buffer_depth;
    std::vector<uint8_t> m_buffer_video;
    std::vector<uint16_t> m_gamma;
    Mutex m_rgb_mutex;
    Mutex m_depth_mutex;
    bool m_new_rgb_frame;
    bool m_new_depth_frame;
};

Freenect::Freenect freenect;
MyFreenectDevice* device;
freenect_video_format requested_format(FREENECT_VIDEO_RGB);
...

我收到指令Freenect::Freenect freenect;的错误无法解析标识符freenect

该模板的代码位于 libfreenect.hpp 代码中:

class Freenect : Noncopyable {
  private:
    typedef std::map<int, FreenectDevice*> DeviceMap;
  public:
  ...
    template <typename ConcreteDevice>
    ConcreteDevice& createDevice(int _index) {
        DeviceMap::iterator it = m_devices.find(_index);
        if (it != m_devices.end()) delete it->second;
        ConcreteDevice * device = new ConcreteDevice(m_ctx, _index);
        m_devices.insert(std::make_pair<int, FreenectDevice*>(_index, device));
        return *device;
    }
    ... 
}

我不知道问题是什么,这是官方代码,它应该可以工作..有什么建议吗?提前致谢

I have a problem with the code OpenKinect provides. I'm trying to use the Kinect with c++, but I get this error. On the web this question was already asked, but I have not find a decent answer. The code is this:

#include <cstdlib>
#include "libfreenect.h"
#include "libfreenect.hpp"
#include <pthread.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cmath>
#include <vector>
#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif

using namespace std;

class Mutex {
    ...
};

class MyFreenectDevice : public Freenect::FreenectDevice {
    public:
    MyFreenectDevice(freenect_context *_ctx, int _index)
    : Freenect::FreenectDevice(_ctx, _index),
               m_buffer_depth(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
               m_buffer_video(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
               m_gamma(2048),
               m_new_rgb_frame(false),
               m_new_depth_frame(false)
    {
        for (unsigned int i = 0; i < 2048; i++) {
            float v = i / 2048.0;
            v = std::pow(v, 3) * 6;
            m_gamma[i] = v * 6 * 256;
        }
    }
    ...

    private:
    std::vector<uint8_t> m_buffer_depth;
    std::vector<uint8_t> m_buffer_video;
    std::vector<uint16_t> m_gamma;
    Mutex m_rgb_mutex;
    Mutex m_depth_mutex;
    bool m_new_rgb_frame;
    bool m_new_depth_frame;
};

Freenect::Freenect freenect;
MyFreenectDevice* device;
freenect_video_format requested_format(FREENECT_VIDEO_RGB);
...

I get the error Unable to resolve identifier identifier freenect for the instruction Freenect::Freenect freenect;.

The code of this template is in the libfreenect.hpp code:

class Freenect : Noncopyable {
  private:
    typedef std::map<int, FreenectDevice*> DeviceMap;
  public:
  ...
    template <typename ConcreteDevice>
    ConcreteDevice& createDevice(int _index) {
        DeviceMap::iterator it = m_devices.find(_index);
        if (it != m_devices.end()) delete it->second;
        ConcreteDevice * device = new ConcreteDevice(m_ctx, _index);
        m_devices.insert(std::make_pair<int, FreenectDevice*>(_index, device));
        return *device;
    }
    ... 
}

I have no idea of what is the problem, this is the official code and it should work.. any suggestions? thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文