ofxKinect(libfreenect)から得られるdepthが更新されなくなった時の対処方
Kinectハックの話。
MacOSX+openNIがまだ安定動作しない*1のでlibfreenect(ofxKinect)を使っているわけですが、こっちも問題があって、数分動作させ続けていると得られるdepthと光学映像が更新されなくなる。
その状態でkinect.close, kinect.openすると元の状態に復帰するのがわかったので次の関数を作って逃げた。ピクセルデータの比較はもっと簡単な方法があるはずなのでopenCVの調査をしたい。
void testApp::checkDepthUpdated(){ // 300フレームに一回チェックする if (frameCount % 300 == 0) { unsigned char * nextDepth = kinect.getDepthPixels(); if (frameCount != 300) { unsigned char * currentDepthPixels = checkGrayImage.getPixels(); int pixNum = kinect.width * kinect.height; for (int i=0; i<pixNum; i++) { // ピクセルデータを比較 if (nextDepth[i] != currentDepthPixels[i]) { break; } if (i > pixNum / 2) { std::cout << "Depth pixels did not updated!!" << endl; kinect.close(); kinect.open(); kinect.setCameraTiltAngle(angle); break; } } } // 次回比較用に取っておく checkGrayImage.setFromPixels(nextDepth, kinect.width, kinect.height); } }
もっとスマートな方法があったら教えてください!!
*1:時々クラッシュする