我有 kinect 与 openni 和 opencv 一起运行。我已经使用网络摄像头使用 haarcascade 进行了面部检测,但我无法使用 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 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;
}
...有人请帮帮我