掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
kinectを用いた深度バッファの表示 (ID:72657)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
kinectを用いた深度バッファ画像を下記のソースで表示したいのですが、言画像は表示されたのに深度画像が表示されません。表示方法を教えてください。 #include <stdio.h> #include <conio.h> // for _kbhit and _getch #include <cv.h> #include <highgui.h> #include "Kinect-win32.h" #pragma comment (lib,"cv200.lib") #pragma comment (lib,"highgui200.lib") #pragma comment (lib,"cxcore200.lib") #pragma comment (lib,"Kinect.lib") // The "Kinect" Project has been added to the project dependencies of this project. // the listener callback object. Implement these methods to do your own processing class Listener: public Kinect::KinectListener { public: virtual void KinectDisconnected(Kinect::Kinect *K) { printf("Kinect disconnected!\n"); }; // Depth frame reception complete. this only means the transfer of 1 frame has succeeded. // No data conversion/parsing will be done until you call "ParseDepthBuffer" on the kinect // object. This is to prevent needless processing in the wrong thread. virtual void DepthReceived(Kinect::Kinect *K) { K->ParseDepthBuffer(); // K->mDepthBuffer is now valid and usable! // see Kinect-Demo.cpp for a more complete example on what to do with this buffer }; // Color frame reception complete. this only means the transfer of 1 frame has succeeded. // No data conversion/parsing will be done until you call "ParseColorBuffer" on the kinect // object. This is to prevent needless processing in the wrong thread. virtual void ColorReceived(Kinect::Kinect *K) { K->ParseColorBuffer(); // K->mColorBuffer is now valid and usable! // see Kinect-Demo.cpp for a more complete example on what to do with this buffer }; // not functional yet: virtual void AudioReceived(Kinect::Kinect *K) {}; }; int main(int argc, char **argv) { Kinect::KinectFinder KF; if (KF.GetKinectCount() < 1) { printf("Unable to find Kinect devices... Is one connected?\n"); return 0; } Kinect::Kinect *K = KF.GetKinect(); if (K == 0) { printf("error getting Kinect...\n"); return 0; }; // create a new Listener instance Listener *L = new Listener(); // register the listener with the kinect. Make sure you remove the // listener before deleting the instance! A good place to unregister // would be your listener destructor. K->AddListener(L); // SetMotorPosition accepts 0 to 1 range K->SetMotorPosition(1); // Led mode ranges from 0 to 7, see the header for possible values K->SetLedMode(Kinect::Led_Yellow); // Grab 10 accelerometer values from the kinect float x,y,z; for (int i =0 ;i<10;i++) { if (K->GetAcceleroData(&x,&y,&z)) { printf("accelerometer reports: %f,%f,%f\n", x,y,z); } Sleep(5); }; //////////////////// IplImage* depthImage16U = cvCreateImage(cvSize(Kinect::KINECT_DEPTH_WIDTH, Kinect::KINECT_DEPTH_HEIGHT), IPL_DEPTH_16U, 1); // 深度バッファ IplImage* depthImage8U = cvCreateImage(cvSize(Kinect::KINECT_DEPTH_WIDTH, Kinect::KINECT_DEPTH_HEIGHT), IPL_DEPTH_8U, 1); IplImage* colorImage = cvCreateImage(cvSize(Kinect::KINECT_COLOR_WIDTH, Kinect::KINECT_COLOR_HEIGHT), IPL_DEPTH_8U, 3); // 画像バッファ int depth_memsize = Kinect::KINECT_DEPTH_WIDTH * Kinect::KINECT_DEPTH_HEIGHT * sizeof(short); // 深度バッファメモリサイズ int color_memsize = Kinect::KINECT_COLOR_WIDTH * Kinect::KINECT_COLOR_HEIGHT * 3 * sizeof(unsigned char); // 画像バッファメモリサイズ cvNamedWindow("depthbuf", CV_WINDOW_AUTOSIZE); cvNamedWindow("colorbuf", CV_WINDOW_AUTOSIZE); int c = 0; double scale = 255.0 / 2047.0; ////////////////////////////////while文はじまり while(1){ // 深度バッファの取得 memcpy(depthImage16U->imageData, K->mDepthBuffer, depth_memsize); cvConvertScaleAbs(depthImage16U, depthImage8U, scale); // 表示用に8bitへ変換 // 画像バッファの取得 memcpy(colorImage->imageData, K->mColorBuffer, color_memsize); cvCvtColor(colorImage, colorImage, CV_RGB2BGR); // RGBの順に並んでいるのでBGRへ変換 // バッファの表示 cvShowImage("depthbuf", depthImage8U); cvShowImage("colorbuf", colorImage); // 終了判定(ESCキーで終了) c = cvWaitKey(2); if(c == '\x1b'){ break; } } ////////////////////////////////while文おわり cvDestroyAllWindows(); cvReleaseImage(&depthImage16U); cvReleaseImage(&depthImage8U); cvReleaseImage(&colorImage); ///////////////////// printf("press any key to quit..."); while (!_kbhit()) { Sleep(5); }; _getch(); // remove and delete the listener instance K->RemoveListener(L); delete L; //turn the led off K->SetLedMode(Kinect::Led_Off); // when the KinectFinder instance is destroyed, it will tear down and free all kinects. return 0; };
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.