opencv人脸识别预测错误
opencv face recognition prediction error
我在应用程序中偶然发现了一个无法摆脱的异常。。。
我正在尝试用所有三种人脸识别算法(Eigen、Fisher和LBPH)编写一个简单的图像人脸识别程序。
未处理的异常由以下行引起:
Fisher_prediction = Fisher_model->predict(crop);
错误信息显示:Unhandled exception at at 0x000007FEFDB3A49D in FaceRecognition.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000002782B0.
由msvcr110d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 152 C++
引起
有什么建议我哪里错了吗??
这是代码的其余部分:
Mat frame = imread("1.jpg");
// Apply the classifier to the frame
if (!frame.empty()) {
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
// Detect faces
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));
// Set Region of Interest
cv::Rect roi_b;
cv::Rect roi_c;
size_t ic = 0; // ic is index of current element
int ac = 0; // ac is area of current element
size_t ib = 0; // ib is index of biggest element
int ab = 0; // ab is area of biggest element
// Iterate through all current elements (detected faces)
for (ic = 0; ic < faces.size(); ic++) {
roi_c.x = faces[ic].x;
roi_c.y = faces[ic].y;
roi_c.width = (faces[ic].width);
roi_c.height = (faces[ic].height);
ac = roi_c.width * roi_c.height; // Get the area of current element (detected face)
roi_b.x = faces[ib].x;
roi_b.y = faces[ib].y;
roi_b.width = (faces[ib].width);
roi_b.height = (faces[ib].height);
ab = roi_b.width * roi_b.height; // Get the area of biggest element, at beginning it is same as "current" element
if (ac > ab) {
ib = ic;
roi_b.x = faces[ib].x;
roi_b.y = faces[ib].y;
roi_b.width = (faces[ib].width);
roi_b.height = (faces[ib].height);
}
crop = frame(roi_b);
cv::resize(crop, res, Size(img_width, img_height), 0, 0, INTER_LINEAR); // This will be needed later while saving images
cvtColor(crop, gray, CV_BGR2GRAY); // Convert cropped image to Grayscale
Point pt1(faces[ic].x, faces[ic].y); // Display detected faces on main window - live stream from camera
Point pt2((faces[ic].x + faces[ic].height), (faces[ic].y + faces[ic].width));
//rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0);
/* Calculate the position for annotated text */
int pos_x = std::max(roi_b.tl().x - 10, 0);
int pos_y = std::max(roi_b.tl().y - 10, 0);
if(createdFisher) {
Fisher_prediction = Fisher_model->predict(crop);
QString Fisher_qs = QString::number(Fisher_prediction);
/* Create the text we will annotate the box with */
string Fisher_text = format("Prediction Fisherfaces = %d", Fisher_prediction);
putText(frame, Fisher_text, Point(pos_x, pos_y), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0), 2.0);
/* Draw a green rectangle around the detected face */
rectangle(frame, pt1, pt2, MATCH_COLOR, 1);
ui.txtConsole->appendPlainText(QString("Fisherfaces - " + Fisher_qs));
}
if(createdEigen) {
Eigen_prediction = Eigen_model->predict(crop);
QString Eigen_qs = QString::number(Eigen_prediction);
/* Create the text we will annotate the box with */
string Eigen_text = format("Prediction Eigenfaces = %d", Eigen_prediction);
putText(frame, Eigen_text, Point(pos_x, pos_y), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0), 2.0);
/* Draw a green rectangle around the detected face */
rectangle(frame, pt1, pt2, MATCH_COLOR, 1);
ui.txtConsole->appendPlainText(QString("Eigenfaces - " + Eigen_qs));
}
if(createdLBPH) {
LBPH_prediction = LBPH_model->predict(crop);
QString LBPH_qs = QString::number(LBPH_prediction);
/* Create the text we will annotate the box with */
string LBPH_text = format("Prediction LBPH = %d", LBPH_prediction);
putText(frame, LBPH_text, Point(pos_x, pos_y), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0), 2.0);
/* Draw a green rectangle around the detected face */
rectangle(frame, pt1, pt2, MATCH_COLOR, 1);
ui.txtConsole->appendPlainText(QString("Linear Binary Patern Histogram - " + LBPH_qs));
}
}
putText(frame, text, cvPoint(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(0, 0, 255), 1, CV_AA);
imshow("original", frame);
if (!crop.empty()) {
imshow("detected", crop);
}
else
destroyWindow("detected");
}
int c = waitKey(0);
所有必要的#include和变量以及分类器都在程序开始时初始化。
我做错的是,我将一张未调整大小的图片传递给人脸识别器(我在数据库中使用的图片为200x200px),因此算法无法基于比数据库中更大分辨率的图像进行人脸识别。
相关文章:
- 从udp接收帧对于人脸识别来说太慢
- 哗啦��错误:无法识别任何一组可以驱动指定关节的控制器
- 每次b/c程序无法加载级联时,使用harr级联的人脸识别都会失败
- GCC-7:错误:无法识别的命令行选项"-M64"
- 人脸识别:每个人的所有图像都必须相同吗?
- 在C++中找不到人脸识别器
- if 语句错误地识别括号中的空格
- 如何在opencv3中使用UMat来训练人脸识别
- 如何从视频中识别人脸识别中的未知人员
- OpenCV 错误 5772.人脸识别
- 我在哪里可以找到完整的img包,用于训练opencv人脸识别系统?
- 人脸识别器OpenCV
- 在使用和执行OpenCV的人脸识别时需要帮助
- mex 编译错误: 无法识别的开关: -cxx
- 加载经过训练的人脸识别器模型
- 人脸识别器未在此范围内声明
- 训练人脸识别器需要花费大量时间
- 用于人脸识别的特征面算法.如何识别面部是否在任何类别中没有锥体
- 人脸识别开放式CV视觉工作室理解
- opencv人脸识别预测错误