2011-06-13 13 views
-1

저는 C++ 프로그래머가 아니지만 아래 코드를 컴파일하고 싶습니다. g ++에서 오류가 발생했습니다.cpp 코드에서 오류가 발생했습니다.

opencv.cpp: In function ‘int main(int, char**)’: 
opencv.cpp:111: error: missing template arguments before ‘freenect’ 
opencv.cpp:111: error: expected ‘;’ before ‘freenect’ 
opencv.cpp:112: error: ‘freenect’ was not declared in this scope 
opencv.cpp:112: error: expected primary-expression before ‘>’ token 



    #include "libfreenect.hpp" 
    #include <iostream> 
    #include <vector> 
    #include <cmath> 
    #include <pthread.h> 
    #include <cv.h> 
    #include <cxcore.h> 
    #include <highgui.h> 

    using namespace cv; 
    using namespace std; 

    class Mutex { 
    public: 
     Mutex() { 
      pthread_mutex_init(&m_mutex, NULL); 
     } 
     void lock() { 
      pthread_mutex_lock(&m_mutex); 
     } 
     void unlock() { 
      pthread_mutex_unlock(&m_mutex); 
     } 
    private: 
     pthread_mutex_t m_mutex; 
    }; 

    class MyFreenectDevice : public Freenect::FreenectDevice { 
     public: 
     MyFreenectDevice(freenect_context *_ctx, int _index) 
      : Freenect::FreenectDevice(_ctx, _index),     m_buffer_depth(FREENECT_DEPTH_11BIT_SIZE),m_buffer_rgb(FREENECT_VIDEO_RGB_SIZE),   m_gamma(2048), m_new_rgb_frame(false), m_new_depth_frame(false), 
       depthMat(Size(640,480),CV_16UC1),   rgbMat(Size(640,480),CV_8UC3,Scalar(0)), ownMat(Size(640,480),CV_8UC3,Scalar(0)) 
     { 
      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; 
      } 
     } 
     // Do not call directly even in child 
     void VideoCallback(void* _rgb, uint32_t timestamp) { 
      std::cout << "RGB callback" << std::endl; 
      m_rgb_mutex.lock(); 
      uint8_t* rgb = static_cast<uint8_t*>(_rgb); 
      rgbMat.data = rgb; 
      m_new_rgb_frame = true; 
      m_rgb_mutex.unlock(); 
     }; 
     // Do not call directly even in child 
     void DepthCallback(void* _depth, uint32_t timestamp) { 
      std::cout << "Depth callback" << std::endl; 
      m_depth_mutex.lock(); 
      uint16_t* depth = static_cast<uint16_t*>(_depth); 
      depthMat.data = (uchar*) depth; 
      m_new_depth_frame = true; 
      m_depth_mutex.unlock(); 
     } 

     bool getVideo(Mat& output) { 
    m_rgb_mutex.lock(); 
      if(m_new_rgb_frame) { 
       cv::cvtColor(rgbMat, output, CV_RGB2BGR); 
       m_new_rgb_frame = false; 
       m_rgb_mutex.unlock(); 
       return true; 
      } else { 
       m_rgb_mutex.unlock(); 
       return false; 
      } 
     } 

     bool getDepth(Mat& output) { 
       m_depth_mutex.lock(); 
       if(m_new_depth_frame) { 
        depthMat.copyTo(output); 
        m_new_depth_frame = false; 
        m_depth_mutex.unlock(); 
        return true; 
       } else { 
        m_depth_mutex.unlock(); 
        return false; 
       } 
      } 

     private: 
     std::vector<uint8_t> m_buffer_depth; 
     std::vector<uint8_t> m_buffer_rgb; 
     std::vector<uint16_t> m_gamma; 
     Mat depthMat; 
     Mat rgbMat; 
     Mat ownMat; 
     Mutex m_rgb_mutex; 
     Mutex m_depth_mutex; 
     bool m_new_rgb_frame; 
     bool m_new_depth_frame; 
    }; 



    int main(int argc, char **argv) { 
     bool die(false); 
     string filename("snapshot"); 
     string suffix(".png"); 
     int i_snap(0),iter(0); 

     Mat depthMat(Size(640,480),CV_16UC1); 
     Mat depthf (Size(640,480),CV_8UC1); 
     Mat rgbMat(Size(640,480),CV_8UC3,Scalar(0)); 
     Mat ownMat(Size(640,480),CV_8UC3,Scalar(0)); 

    Freenect::Freenect freenect; 
    MyFreenectDevice& device = freenect.createDevice<MyFreenectDevice>(0); 

namedWindow("rgb",CV_WINDOW_AUTOSIZE); 
namedWindow("depth",CV_WINDOW_AUTOSIZE); 
device.startVideo(); 
device.startDepth(); 
while (!die) { 
    device.getVideo(rgbMat); 
    device.getDepth(depthMat); 
    cv::imshow("rgb", rgbMat); 
    depthMat.convertTo(depthf, CV_8UC1, 255.0/2048.0); 
    cv::imshow("depth",depthf); 
    char k = cvWaitKey(5); 
    if(k == 27){ 
     cvDestroyWindow("rgb"); 
     cvDestroyWindow("depth"); 
     break; 
    } 
    if(k == 8) { 
     std::ostringstream file; 
     file << filename << i_snap << suffix; 
     cv::imwrite(file.str(),rgbMat); 
     i_snap++; 
    } 
    if(iter >= 1000) break; 
    iter++; 
} 

device.stopVideo(); 
device.stopDepth(); 
return 0; 
    } 
+0

죄송합니다. 맞춤형 디버거가 아닙니다. 너는 약간의 노력을 기울여야한다. –

+4

아마도 111 행에서 "freenect"전에 템플릿 인자가 누락 된 것입니까? – trutheality

+0

그리고 어떤 라인이 111입니까? 나는 그 정도까지 세지 않을 것이다. –

답변

2

최소한의 작업 예제를 만드는 방법에 대해 읽어 보시기 바랍니다. 제공된 코드가 너무 크지 만 최소한의 코드는 아닙니다.

코드는 당신이 libfreenect.hpp의 내용을 제공하지 않았기 때문에, 잘못되었는지 정확히 무슨 말을 조금 어렵 라인 Freenect::Freenect freenect;

에 실패했습니다. 오류 메시지는 약간의 단서를 제공합니다. Freenect :: Freenect는 템플릿이고, 당신은 그렇게 호출하지 않았습니다.

관련 문제