2011-03-03 41 views
0

我正在嘗試使用Kinect(OpenNI)製作應用程序,使用GUI處理圖像(OpenCV)。OpenNI + OpenCV + Qt

我測試德OpenNI + OpenCV的和OpenCV + Qt的

通常情況下,當我們使用的OpenCV + Qt中,我們可以做一個QWidget顯示相機(VideoCapture)的內容。捕獲框架和更新此查詢設備的新幀。

在OpenNI和OpenCV中,我看到了使用for循環從Kinect傳感器(圖像,深度)中提取數據的示例,但我不知道如何使這個拉動路由模式變得簡單。我的意思是,類似於OpenCV幀查詢。

這個想法嵌入在QWidget中從Kinect中捕獲的圖像。 QWidget將有(現在)2個按鈕「啓動Kinect」和「退出」......並在繪畫部分下方顯示捕獲的數據。

任何雖然?

回答

0

您可以嘗試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(); 

然後要查詢框架,您可以使用標籤小部件。我正在發佈一個示例代碼如下:

// 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));