我使用openni和opencv运行kinect。我用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;
}
......有人请帮帮我
答案 0 :(得分:0)
cvHaarDetectObjects仅适用于灰度图像或CV_8U类型的矩阵。
因此,您必须在从Kinect检索RGB图像后进行转换。
cvtColor( frame, frame_gray, CV_BGR2GRAY );
另外,我看到你将depthMap命名为RGB图像,可能会让人感到困惑。