i have kinect running with openni and opencv. i have done facedetection with haarcascade with a webcam but i'm not able to do it with kinect
int main( int argc, char* argv[] ){
try
{
... // call OpenCV
VideoCapture capture( CV_CAP_OPENNI );
CvHaarClassifierCascade* cascade=0;
CvMemStorage* storage=0;
CvSeq* face;
storage=cvCreateMemStorage(0);
cascade=(CvHaarClassifierCascade *)cvLoad("haarcascade_profileface.xml",0,0,0);*/
if(cascade){
for(;;)
{
Mat depthMap;
if( !capture.grab() )
{
cout << "Can not grab images." << endl;
return -1;
}
else
{
if( capture.retrieve( depthMap,CV_CAP_OPENNI_BGR_IMAGE) )
{
/*IplImage* img = new IplImage(depthMap);
face=cvHaarDetectObjects(img,cascade,storage,1.1,3,CV_HAAR_DO_CANNY_PRUNING,cvSize(0,0));
for(int i=0;i<(face?face->total:0);i++)
{
CvRect* r=(CvRect*)cvGetSeqElem(face,i);
CvPoint pt1={r->x,r->y};
CvPoint pt2={r->x+r->width,r->y+r->height};
cvRectangle(img,pt1,pt2,CV_RGB(0,255,0),3,4,0);
//imshow( "depth map", depthMap);
}*/
const float开发者_StackOverflow社区 scaleFactor = 0.05f;
//Mat show; depthMap.convertTo( show, CV_8UC3, scaleFactor );
imshow( "depth map", depthMap);
// }
}
if( waitKey( 30 ) >= 0 )
break;
}
}
}
catch( cv::Exception& e )
{
const char* err_msg = e.what();
std::cout << "exception caught: " << err_msg << std::endl;
}
return 0;
}
...somebody please help me out
cvHaarDetectObjects only works for gray scale images, or Matrix of the type CV_8U.
So you must do the conversion after retrieving RGB image from Kinect.
cvtColor( frame, frame_gray, CV_BGR2GRAY );
Also I see you naming depthMap to an RGB image, it might be confusing.
精彩评论