OpenCV 人脸识别返回太多人脸
OpenCV face deteciton returns too many faces
我有一点问题。我正在尝试通过 Kinect v1 进行人脸检测。我从kinect获取数据并将其转换为OpenCV垫。然后我尝试检测图像中的人脸,但函数返回 face.size() = cca 250000000。你知道问题出在哪里吗?
void getKinectData(GLubyte* dest) {
NUI_IMAGE_FRAME imageFrame; //structure of frame ( number,res etc )
NUI_LOCKED_RECT LockedRect; //pointer to actual data
if (sensor->NuiImageStreamGetNextFrame(rgbStream, 0, &imageFrame) < 0) return;
INuiFrameTexture* texture = imageFrame.pFrameTexture; // manages the frame data
texture->LockRect(0, &LockedRect, NULL, 0);
IplImage* image = cvCreateImageHeader(cvSize(COLOR_WIDTH, COLOR_HIGHT), IPL_DEPTH_8U, 4);
if (LockedRect.Pitch != 0) // pitch - how many bytes are in each row of the frame
{
BYTE* curr = (BYTE*)LockedRect.pBits;
cvSetData(image, curr, LockedRect.Pitch);
const BYTE* dataEnd = curr + (widthX*heightX) * 4;
while (curr < dataEnd) {
*dest++ = *curr++;
}
}
//cvShowImage("color image", image);
m = cv::cvarrToMat(image).clone();
DetectAndDisplay(m);
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(rgbStream, &imageFrame);
}
void DetectAndDisplay(cv::Mat frame)
{
std::vector<cv::Rect> faces;
cv::Mat frame_gray;
cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
//-- Detect faces
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(24, 24));
for (size_t i = 0; i < faces.size(); i++)
{
cv::Point center(faces[i].x + faces[i].width / 2, faces[i].y + faces[i].height / 2);
ellipse(frame, center, cv::Size(faces[i].width / 2, faces[i].height / 2), 0, 0, 360, cv::Scalar(255, 0, 255), 4, 8, 0);
cv::Mat faceROI = frame_gray(faces[i]);
std::vector<cv::Rect> eyes;
/*
//-- In each face, detect eyes
eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));
for (size_t j = 0; j < eyes.size(); j++)
{
Point eye_center(faces[i].x + eyes[j].x + eyes[j].width / 2, faces[i].y + eyes[j].y + eyes[j].height / 2);
int radius = cvRound((eyes[j].width + eyes[j].height)*0.25);
circle(frame, eye_center, radius, Scalar(255, 0, 0), 4, 8, 0);
}*/
}
//-- Show what you got
imshow(window_name, frame);
}
我知道
这个老了,但我也有类似的问题,所以我认为其他人可能会受益。
在调试构建期间与发行版opencv_objdetect库链接将导致 detectMultiScale() 返回包含数十万个错误矩形的巨大向量。以下是在Visual Studio 2017中修复它的方法(我使用的是OpenCV版本3.2,因此请调整提到的库的名称以与您正在使用的版本相对应):
- 项目 |(您的项目名称)性能。。。(或右键单击解决方案资源管理器中的项目并选择属性) 将配置更改为"
- 调试",将"平台"更改为"所有平台"(或者可以对每个调试平台分别重复这些步骤)
- 转到链接器 |输入并确保 opencv_objdetect320d.lib 位于添加依赖项列表并删除 opencv_objdetect320.lib 如果它就在那里。
- 对配置 == 发布重复上述步骤,但这次确保链接器 |输入包括 opencv_objdetect320.lib(名称中没有尾随 d)在"添加依赖项"列表中并删除opencv_objdetect320d.lib 如果它在那里。
相关文章:
- 在没有太多条件句的情况下,我如何避免被零除
- 错误:字符数组的初始值设定项太多
- 对象实例化调用构造函数的次数太多
- Levenshtein 两个文件的距离花费了太多时间
- 我有三个 getline,但是一旦编译,输入就太多了
- 将使用太多的纹理插值器 - 带旋转的着色器
- C/C++:socket() 创建在循环中失败,打开的文件太多
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- C++:数组<>初始值设定项太多
- GLib-ERROR:为GWakeup创建管道:打开的文件太多
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 我会导致太多内存泄漏,以至于我的计算机无响应吗?
- ZeroMq:打开的文件太多.在同一对象上连续增长的fd使用数
- 读取串行命令花费太多时间
- 为什么 Boost unordered_map 在第一次插入时需要太多时间?
- BRK(0) 花费的时间是否太多?
- 按扩展名过滤搜索文件会返回太多结果
- OpenCV FREAK 返回了太多的异常值
- libclang返回了太多关于函数声明的信息
- OpenCV 人脸识别返回太多人脸