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}

)
4

1 回答 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 的视差图

于 2016-03-04T03:59:14.373 回答