Python 如何将xBox kinect连接到ubuntu中的opencv? 我想用C++在Ubuntu(14.04)中用OpenCV来处理Kinect。 我安装openni和libfreenect
当我在终端中键入lsusb时,系统会回答我后面的文本Python 如何将xBox kinect连接到ubuntu中的opencv? 我想用C++在Ubuntu(14.04)中用OpenCV来处理Kinect。 我安装openni和libfreenect,python,c++,opencv,ubuntu,kinect,Python,C++,Opencv,Ubuntu,Kinect,当我在终端中键入lsusb时,系统会回答我后面的文本 Bus 003 Device 005: ID 045e:02ae Microsoft Corp. Xbox NUI Camera Bus 003 Device 003: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor Bus 003 Device 004: ID 045e:02ad Microsoft Corp. Xbox NUI Audio Kinect camera test Number of
Bus 003 Device 005: ID 045e:02ae Microsoft Corp. Xbox NUI Camera
Bus 003 Device 003: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 003 Device 004: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Kinect camera test
Number of devices found: 1
当我在终端中键入freenect glview时,系统应答文本会跟着我
Bus 003 Device 005: ID 045e:02ae Microsoft Corp. Xbox NUI Camera
Bus 003 Device 003: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 003 Device 004: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Kinect camera test
Number of devices found: 1
系统显示RGB和深度
另外,我在cmake opencv(-D WITH_openni:ON)和系统显示以下内容后激活了openni:
openni: yes
prime-sensor-kinect : yes
我通过以下方式编译代码:
g++ -o test1 test1.cpp `pkg-config opencv --cflags --libs`
但当我运行代码时,系统错误:
CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate production trees: Can't create
CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate production trees: Can't create any node of the requested type!
0.0
Unable to Retrieve Disparity Map from camera
请求类型的任何节点
代码:
python代码:
import cv2
import cv2.cv as cv
capture = cv2.VideoCapture(cv.CV_CAP_OPENNI)
capture.set(cv.CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, cv.CV_CAP_OPENNI_VGA_30HZ)
print capture.get(cv.CV_CAP_PROP_OPENNI_REGISTRATION)
while True:
if not capture.grab():
print "Unable to Grab Frames from camera"
break
okay1, depth_map = capture.retrieve(0,cv.CV_CAP_OPENNI_DEPTH_MAP)
if not okay1:
print "Unable to Retrieve Disparity Map from camera"
break
okay2, gray_image = capture.retrieve(0,cv.CV_CAP_OPENNI_GRAY_IMAGE)
if not okay2:
print "Unable to retrieve Gray Image from device"
break
cv2.imshow("depth camera", depth_map)
cv2.imshow("rgb camera", gray_image)
if cv2.waitKey(10) == 27:
break
cv2.destroyAllWindows()
capture.release()
opencv不将kinect识别为输入设备。如何解决此问题
我很抱歉写得不好,因为我的英语不好 如果已安装libfreenect和opencv,则应该能够运行以下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:
orig = freenect.sync_get_video()[0]
orig = cv2.cvtColor(orig,cv2.COLOR_BGR2RGB)
dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
cv2.imshow('Disparity', dst)
cv2.imshow('RGB',orig)
if cv2.waitKey(1) & 0xFF == ord('b'):
break
当我发现自己处于类似的情况时,我偶然发现了这条线索。我只能在为OpenNI安装PrimeSense模块后才能从OpenCV获取传感器数据,您可以找到。遵循系统自述文件(Ubuntu 14.04.5)中列出的说明后,我可以设法运行以下代码:
#include <cstdio>
#include <opencv2/opencv.hpp>
int main(int argc, char **argv){
cv::VideoCapture capture(CV_CAP_OPENNI);
cv::Mat image;
cv::Mat bgrImage;
while(true){
capture.grab();
capture.retrieve(image, CV_CAP_OPENNI_DEPTH_MAP);
capture.retrieve(bgrImage, CV_CAP_OPENNI_BGR_IMAGE);
imshow("Image", image);
imshow("Color", bgrImage);
if(cv::waitKey(30) >= 0) break;
}
return 0;
}
#包括
#包括
int main(int argc,字符**argv){
视频捕获捕获(cv_CAP_OPENNI);
cv::Mat图像;
cv::Mat bgrImage;
while(true){
capture.grab();
捕获、检索(图像、CV、CAP、OPENNI、深度图);
捕获、检索(bgrImage、CV\u CAP\u OPENNI\u BGR\u图像);
imshow(“图像”,图像);
imshow(“颜色”,bgrImage);
如果(cv::waitKey(30)>=0)中断;
}
返回0;
}