如何在 ubuntu 中将 xBox kinect 连接到 opencv?
how to connect xBox kinect to opencv in ubuntu?
我想在 ubuntu (14.04) 中通过 C++ 与 openCV 一起工作。
我安装了 openni 和 libfreenect。
当我在终端中输入 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
当我在终端中键入 freenect-glview 时,系统会向我显示答案文本。
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
任何请求类型的节点!
代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <vector>
#include <stdio.h>
using namespace cv;
int main(int, char**)
{
VideoCapture cap(CV_CAP_OPENNI); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
并且在运行python代码时,系统错误:
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作为输入device.How解决这个问题?
很抱歉写得不好,因为我的英语不好。
如果您安装了 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 获取传感器数据,您可以找到 here。按照我的系统 (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;
}
我想在 ubuntu (14.04) 中通过 C++ 与 openCV 一起工作。 我安装了 openni 和 libfreenect。
当我在终端中输入 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
当我在终端中键入 freenect-glview 时,系统会向我显示答案文本。
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
任何请求类型的节点!
代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <vector>
#include <stdio.h>
using namespace cv;
int main(int, char**)
{
VideoCapture cap(CV_CAP_OPENNI); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
并且在运行python代码时,系统错误:
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作为输入device.How解决这个问题?
很抱歉写得不好,因为我的英语不好。
如果您安装了 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 获取传感器数据,您可以找到 here。按照我的系统 (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;
}