我正在尝试使用带有以下代码的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) );
}
为什么会发生这种情况?
谢谢!
答案 0 :(得分:0)
请确保按照以下步骤使用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);
}