首页 文章

无法访问Kinect传感器凸轮使用Opencv和libfreenect驱动程序在Ubuntu平台上

提问于
浏览
1

我在Ubuntu平台上使用OpenCv和OpenKinect来访问Kinect传感器 . 主要错误是: undefined reference to `freenect_sync_get_rgb_cv' 帮我调试此错误 . 源代码如下:

#include <iostream>
#include <cv.h>
#include <opencv/highgui.h>
 // OpenKinect Header files
#include <libfreenect.h>
#include <libfreenect_sync.h>
#include <libfreenect/libfreenect_cv.h>
// --- C++ ---
#include <stdio.h>
#include <fstream>
#include <vector>
#include <math.h>
#include <iostream>
#include <vector>
#include <opencv2/highgui.hpp>

using namespace std;
using namespace cv;
char key;
// IplImage *freenect_sync_get_depth_cv(int index);
// IplImage *freenect_sync_get_rgb_cv(int index);
int main(int argc, char** argv)
{
IplImage*        image = NULL;
 /* create a window */
    cvNamedWindow("Camera_Output", 1); 
    while(1) {
         image = freenect_sync_get_rgb_cv(0);
       // Mat image(freenect_sync_get_rgb_cv(0));
        //CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
       // cvCvtColor(image, image, CV_RGB2BGR); // cvLoadImage( freenect_sync_get_rgb_cv(0) ) 
       // VideoCapture::grab

       //cvCreateImage(cvSize(640, 480), 8, 4);

       cvShowImage("Camera_Output", image);
       if (!image) {
                printf("Error: Kinect not connected?\n");
                return -1;
            }

        key = cvWaitKey(100);     //Capture Keyboard stroke
        if (char(key) == 27){
            break; 

        }
        }
    /* free memory */
    cvDestroyWindow( "video" ); 
    return 0;
}

错误看起来像:

[100%] Building CXX object CMakeFiles/KinectRGB.dir/KinectRGB.cpp.o
Linking CXX executable KinectRGB
CMakeFiles/KinectRGB.dir/KinectRGB.cpp.o: In function `main':
KinectRGB.cpp:(.text+0x2c): undefined reference to `freenect_sync_get_rgb_cv'
collect2: error: ld returned 1 exit status
make[2]: *** [KinectRGB] Error 1
make[1]: *** [CMakeFiles/KinectRGB.dir/all] Error 2
make: *** [all] Error 2
sincos@sincos-300E4C-300E5C-300E7C:~/Desktop/OpenCV_test/KinectRead/build$

构建代码的CMakeLists.txt文件如下:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

project(KinectRGB)

set(DEPENDENCIES OpenCV GLUT OpenGL)

message("\n")
foreach( DEP ${DEPENDENCIES} )

    find_package( ${DEP} )

   string( TOUPPER ${DEP} UDEP ) # Capitalize
   if( ${DEP}_FOUND OR ${UDEP}_FOUND )
       message("\n${DEP}_Found = TRUE\n")
     endif() 

find_package(Threads REQUIRED)
find_package(libfreenect REQUIRED)
include_directories("/usr/include/libusb-1.0/")
endforeach()


include_directories( 

    ${FREENECT_INCLUDE_DIR}
    ${GLUT_INCLUDE_DIR}
    ${OPENGL_INCLUDE_DIR}
    ${OpenCV_INCLUDE_DIRS}
)

add_executable(KinectRGB KinectRGB.cpp) 

target_link_libraries(KinectRGB

    ${FREENECT_LIBRARIES} 
    ${GLUT_LIBRARY} 
    ${OPENGL_LIBRARIES} 
    ${OpenCV_LIBS}
    ${CMAKE_THREAD_LIBS_INIT}

)

1 回答

  • 0

    我不建议使用IplImage . 它是一种原始类型 . 要测试您的Kinect是否正常工作,请运行以下python脚本:

    import freenect
    import cv2
    import numpy as np
    from functions import *
    
    def nothing(x):
        pass   
    kernel = np.ones((5, 5), np.uint8)     
    
    def pretty_depth(depth):
        np.clip(depth, 0, 2**10 - 1, depth)
        depth >>= 2
        depth = depth.astype(np.uint8)
        return depth
    
    while 1:
    
        dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
        cv2.imshow('Video', dst)
        if cv2.waitKey(1) & 0xFF == ord('b'):
            break
    

    您应该看到kinect的视差图

相关问题