ofxkinect Exampleメモ(2)
//--------------------------------------------------------------
void testApp::update() {
ofBackground(100, 100, 100);
//kinectからの画像を更新
kinect.update();
// there is a new frame and we are connected
//そこに新しいフレームがあり、我々が接続されている
if(kinect.isFrameNew()) {
// load grayscale depth image from the kinect source
//Kinectのソースからの階調奥行き画像を読み込む //ofxCvGrayscaleImage
grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
//閾値の範囲の深度の物体だけを抽出
// we do two thresholds - one for the far plane and one for the near plane
//ここまで飛行機用と近い平面について1 - 私たちは二つの閾値を行う
// we then do a cvAnd to get the pixels which are a union of the two thresholds
//我々は、2つの閾値の和集合であるピクセルを得るためにcvAndを行う
if(bThreshWithOpenCV) {
grayThreshNear = grayImage;
grayThreshFar = grayImage;
grayThreshNear.threshold(nearThreshold, true);
grayThreshFar.threshold(farThreshold);
cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
} else {
// or we do it ourselves - show people how they can work with the pixels
//あるいは我々はそれを自分自身を行う - ショーの人々を、彼らはピクセルを扱うことができる方法
unsigned char * pix = grayImage.getPixels();//ofxCvGrayscaleImage
int numPixels = grayImage.getWidth() * grayImage.getHeight();
for(int i = 0; i < numPixels; i++) {
if(pix[i] < nearThreshold && pix[i] > farThreshold) {
pix[i] = 255;
} else {
pix[i] = 0;
}
}
}
// update the cv images
//CVイメージを更新
grayImage.flagImageChanged();
// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
//20画素、1/3ワット* H画素の大きさの間にある輪郭を見つける。
// also, find holes is set to true so we will get interior contours as well....
//また、穴を見つけるには私たちは同様に内部の輪郭を取得するtrueに設定されている....
contourFinder.findContours(grayImage, 10, (kinect.width*kinect.height)/2, 20, false);
}
#ifdef USE_TWO_KINECTS
kinect2.update();
#endif
}