kinectを用いた深度バッファの表示

解決


GGG  URL  2011-05-24 17:16:59  No: 72657  IP: 192.*.*.*

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;

};

編集 削除
ホウジョウウサギ  2011-05-24 18:49:19  No: 72658  IP: 192.*.*.*

前の質問
>Kinect-v14-withsourceのデータ保存
の件はその後どうなったのでしょう?
(質問されているのは同じ方ですよね?)

(前の質問にレスしてるのが自分だけなので
  こういうことは言い出しにくいのですが)
前の質問を投げっぱなしにして  次に進むというのは
答えてくれた人に対してちょっと失礼な気がしませんか?



で,今回の質問についてですが,
(この質問の仕方からでは何が起こっているのかこちらにはまるで見当もつきませんので)
かなりいい加減な憶測になりますが,
main()内のwhileループにてタイミング等を考慮せずにmemcpyとかしているように
見受けられますが,そのあたりに問題はないのでしょうか?
リスナー側と互いに動機を取るようにしたら改善しませんか?

編集 削除
επιστημη  URL  2011-05-24 19:50:33  No: 72659  IP: 192.*.*.*

教師のクセに質問下手で礼儀知らず。

編集 削除
GGG  2011-05-24 22:49:51  No: 72660  IP: 192.*.*.*

ホウジョウウサギさん、大変失礼しました。以前の質問に回答を送ってくれてありがとうございます。今だ前回のプログラムは未定義エラーが出ますが、いったん中断して様子を見て、もう1つ悩んでいる、このページに載せたソースのエラー解決に移ります。。

また、この質問のプログラムでは、「VS C++2008」,「OpenCV」,「Xboxのkinect」を用いています。

編集 削除
ホウジョウウサギ  2011-05-25 09:39:05  No: 72661  IP: 192.*.*.*

>この質問のプログラムでは、「VS C++2008」,「OpenCV」,「Xboxのkinect」を用いています
この条件は 前回 と同一ですよね?
で,
今回 は一応動作させるまでこぎつけている
=前回 の問題を 今回 ではクリアしている
のだと思うのですが,違うのでしょうか?

あと,あなたの[HomePage]のリンク先を見るに,
深度情報が取得できているように見えるのですが…??

編集 削除
GGG  2011-05-30 14:48:42  No: 72662  IP: 192.*.*.*

ありがとうございます。みなさんのおかげで解決しました。

編集 削除
επιστημη  URL  2011-05-30 19:39:12  No: 72663  IP: 192.*.*.*

なにが原因で/どのように解決したのでしょうか。

編集 削除