我正在尝试使用Kinect (OpenNI)制作一个应用程序,使用图形用户界面处理图像(OpenCV)。
我测试了de OpenNI+OpenCV和OpenCV+Qt
通常,当我们使用OpenCV+Qt时,我们可以制作一个QWidget来显示摄像机的内容(VideoCapture)。捕获帧并更新此查询,以将新帧发送到设备。
在OpenNI和OpenCV中,我看到了使用for cycle从Kinect传感器拉取数据(图像、深度)的例子,但我不知道如何让这个拉取路由变得简单。我的意思是,类似于OpenCV框架查询。
这个想法是将从Kinect捕获的图像嵌入到QWidget中。QWidget将有(目前)两个按钮“启动Kinect”和“退出”..and下方的绘画部分,以显示捕获的数据。
有什么想法吗?
发布于 2011-12-30 19:44:09
您可以尝试使用QTimer类以固定的时间间隔查询kinect。在我的应用程序中,我使用了以下代码。
void UpperBodyGestures::refreshUsingTimer()
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(MainEventFunction()));
timer->start(30);
}
void UpperBodyGestures::on_pushButton_Kinect_clicked()
{
InitKinect();
ui.pushButton_Kinect->setEnabled(false);
}
// modify the main function to call refreshUsingTimer function
UpperBodyGestures w;
w.show();
w.refreshUsingTimer();
return a.exec();然后,您可以使用label小部件来查询框架。我在下面发布了一个示例代码:
// Query the depth data from Openni
const XnDepthPixel* pDepth = depthMD.Data();
// Convert it to opencv for manipulation etc
cv::Mat DepthBuf(480,640,CV_16UC1,(unsigned char*)g_Depth);
// Normalize Depth image to 0-255 range (cant remember max range number so assuming it as 10k)
DepthBuf = DepthBuf / 10000 *255;
DepthBuf.convertTo(DepthBuf,CV_8UC1);
// Convert opencv image to a Qimage object
QImage qimage((const unsigned char*)DepthBuf.data, DepthBuf.size().width, DepthBuf.size().height, DepthBuf.step, QImage::Format_RGB888);
// Display the Qimage in the defined mylabel object
ui.myLabel->setPixmap(pixmap.fromImage(qimage,0).scaled(QSize(300,300), Qt::KeepAspectRatio, Qt::FastTransformation));https://stackoverflow.com/questions/5176069
复制相似问题