OpenCV无法从Kinect检测人脸

OpenCV not detecting faces from Kinect

本文关键字:检测 Kinect OpenCV      更新时间:2023-10-16

我正试着用下面的代码检测kinect的人脸。OpenCV的detectMultiScale()在我使用电脑的相机时可以正确地检测人脸,但它似乎不能与kinect的图像一起工作。

Device device;
VideoFrameRef colorFrame;
VideoStream ColorStream;
Mat colorImage, grayScaleFrame;
colorStream.create(device, SENSOR_COLOR );
colorStream.start();

while (1){
    colorStream.readFrame(&colorFrame);
    const RGB888Pixel *imageBuffer = (const RGB888Pixel*)colorFrame.getData();
    colorImage.create(colorFrame.getHeight(), colorFrame.getWidth(), CV_8UC3);
    memcpy(colorImage.data, imageBuffer, 3 * colorFrame.getHeight() * colorFrame.getWidth() * sizeof(uint8_t));
    //face detection
    blur(colorImage, colorImage, Size(2, 2), Point(-1, -1), BORDER_DEFAULT);
    cvtColor(colorImage, grayScaleFrame, CV_BGR2GRAY);
    equalizeHist(grayScaleFrame, grayScaleFrame);
    classifier.detectMultiScale(grayScaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE,  Size(30, 30) );
}

知道为什么会这样吗?

谢谢!

请确保您按照以下步骤与Kinect/OpenNI(1.5.4.0+)抓取帧:

cv::Mat rgb_image, depth_map;
cv::VideoCapture device.open(CV_CAP_OPENNI);
//set RGB-Depth mapping
device.set(CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, 1.0);
while(1)
{
  device.grab();
  device.retrieve(rgb_image, CV_CAP_OPENNI_BGR_IMAGE);
  device.retrieve(depth_map, CV_CAP_OPENNI_DEPTH_MAP);
}