如何使用kinect和opencv进行人脸检测?
我有 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;
}
...有人请帮助我
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cvHaarDetectObjects 仅适用于灰度图像或 CV_8U 类型的矩阵。
因此,您必须在从 Kinect 检索 RGB 图像后进行转换。
我还看到您将深度图命名为 RGB 图像,这可能会令人困惑。
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.
Also I see you naming depthMap to an RGB image, it might be confusing.