今次想用OpenNi + OpenCV在windows platform上寫一個追蹤手勢的程式
先顯示下點追蹤手部的坐標同抽取一部分手部的depth value吧.
hand segmentation (youtube)
主要ideal就是把segmented hand(一開始在中間)的depth map轉為binary map再轉為contour然後就找出maximum inner circle.這個圓心可以作為下一個frame做segmentation位置.這樣一直追蹤下去.
sample code:
//--find max inner circle
double* dist = new double[candidates.size()];
//check each posibility
for(unsigned int k=0;k<candidates.size();k++){
cv::Point canPoint = candidates[k];
double Mindistant = 1000;
for(unsigned int j=0; j<contours[SecondMaxAreaIndex].size(); j++){
double distant = sqrt(pow((double)(contours[SecondMaxAreaIndex][j].x - canPoint.x),2) +
pow((double)(contours[SecondMaxAreaIndex][j].y - canPoint.y),2));
if(distant < Mindistant)Mindistant = distant;
}
dist[k] = Mindistant;
}
//find max
double Max = dist[0];
int MaxK =0;
for(unsigned int k=0;k<=candidates.size();k++){
if( dist[k] >= Max ){
Max = dist[k];
MaxK = k;
}
}
//circle center
int max_x = candidates[MaxK].x;
int max_y = candidates[MaxK].y;