本文介绍了将Microsoft Kinect与Opencv 3.0.0一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试从Microsoft kinect获得xbox 360的视差图.我安装了opencv 3.0.0和带有libfreenect的openni2.当我运行代码时

Hello I am trying to get disparity maps from a Microsoft kinect for xbox 360. I have opencv 3.0.0 and openni2 with libfreenect installed. When I run my code

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**){

    VideoCapture capture( CAP_OPENNI2 );
    namedWindow("win",1);

    for(;;){
        Mat depthMap;
        capture >> depthMap;
        imshow("win",depthMap);
        if( waitKey( 30 ) >= 0 ) break;
    }

    return 0;
}

我的kinect开始投射IR模式,但随后出现一堆错误

OpenNI2-FreenectDriver: Using libfreenect v0.5.3

OpenNI2-FreenectDriver: Found device freenect://0

OpenNI2-FreenectDriver: Opening device freenect://0

[Stream 70] Negotiated packet size 1920

write_register: 0x0105 <= 0x00

write_register: 0x0006 <= 0x00

write_register: 0x0012 <= 0x03

write_register: 0x0013 <= 0x01

write_register: 0x0014 <= 0x1e

write_register: 0x0006 <= 0x02

write_register: 0x0017 <= 0x00

[Stream 80] Negotiated packet size 1920

write_register: 0x000c <= 0x00

write_register: 0x000d <= 0x01

write_register: 0x000e <= 0x1e

write_register: 0x0005 <= 0x01

[Stream 70] Lost 2 total packets in 0 frames (inf lppf)

[Stream 70] Lost 5 total packets in 0 frames (inf lppf)

write_register: 0x0047 <= 0x00

OpenNI2-FreenectDriver: (ERROR) Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE

OpenCV Error: Unspecified error (CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance! ) in readCamerasParams, file /home/ubuntu/opencv-3.0.0/modules/videoio/src/cap_openni2.cpp, line 379 terminate called after throwing an instance of 'cv::Exception' what(): /home/ubuntu/opencv-3.0.0/modules/videoio/src/cap_openni2.cpp:379: error: (-2) CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance! in function readCamerasParams

Aborted

推荐答案

libfreenect需要修复的错误.

libfreenect a bug fixed required.

cd OpenNI2-FreenectDriver/src vim DepthStream.hpp

cd OpenNI2-FreenectDriver/src vim DepthStream.hpp

第173行中,对XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE的检查期望pDataSize的大小为unsigned long long. 但是,OpenNI2期望使用int32_t(大小8对大小4),因此出现了错误.如果出现以下错误,则不会出现 如果您单独使用OpenNI2或NiTE2,则因为它们不要求此属性.但是,如果您使用OpenCV + OpenNI2, 该财产将被查询.

In line 173, the check for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE expects a pDataSize of size unsigned long long. However, OpenNI2 expects an int32_t (size 8 vs size 4) so an error is in order. This error does not appear if if you use OpenNI2 or NiTE2 alone, since they don't ask for this property. However, if you use OpenCV+OpenNI2, the said property will be queried.

修复.更改大小写为XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE的情况:

Fix. Change the case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE with:

 case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE:    // unsigned long long or unsigned int (for OpenNI2/OpenCV)

    if ( *pDataSize != sizeof(unsigned long long) && *pDataSize != sizeof(unsigned int) )
      {
        LogError("Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE!!!");
        return ONI_STATUS_ERROR;
      } else {
          if( *pDataSize == sizeof(unsigned long long) ) {
              *(static_cast<unsigned long long*>(data)) = ZERO_PLANE_DISTANCE_VAL;
          } else {
              *(static_cast<unsigned int*>(data)) = (unsigned int) ZERO_PLANE_DISTANCE_VAL;
          }
      return ONI_STATUS_OK;
       }

请参见此处

这篇关于将Microsoft Kinect与Opencv 3.0.0一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 00:15