0
我正尝试将我的旧opencv人脸检测代码从使用IplImage结构迁移到使用opencv中的Mat类。面部检测OpenCV + Qt + cvMat
问题是代码在没有Qt代码的情况下工作。 这里是codelite在野蛮C++代码:
void detectFace(Mat& img)
{
std::vector<Rect> faces;
Mat gray;
cvtColor(img, gray, CV_BGR2GRAY);
equalizeHist(gray, gray);
// Face detect
face_cascade.detectMultiScale(gray, faces, 1.1, 2,1 | CV_HAAR_SCALE_IMAGE, Size(100,100));
for (unsigned int i = 0; i < faces.size(); i++)
{
//face detect rectangle
Point upperLeftFace(faces[i].x, faces[i].y);
Point lowerRightFace(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
rectangle(/*Matrice*/img, /*Rect*/upperLeftFace, /*Rect*/lowerRightFace, /*BGR Color*/Scalar(255, 255,0), /*Line height*/1, /*line type*/8);
}
//Show window
namedWindow("Alexey Eye", CV_WINDOW_AUTOSIZE);
imshow("Alexey Eye", img);
}
这里是代码,当我使用QT:
void Neski::m_faceDetect()
{
*att_CamCapture >> att_MatCamera;
std::vector<Rect> faces;
Mat grayMat;
cvtColor(att_MatCamera, grayMat, CV_BGR2GRAY);
equalizeHist(grayMat, grayMat);
// Face detect
face_cascade.detectMultiScale(grayMat, faces, 1.1, 2,1 | CV_HAAR_SCALE_IMAGE, Size(150,150));
for (unsigned int i = 0; i < faces.size(); i++)
{
//face detect rectangle
Point upperLeftFace(faces[i].x, faces[i].y);
Point lowerRightFace(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
rectangle(/*Matrice*/att_MatCamera, /*Rect*/upperLeftFace, /*Rect*/lowerRightFace, /*BGR Color*/Scalar(255, 255,0), /*Line height*/1, /*line type*/8);
}
cvtColor(att_MatCamera, att_MatCamera, CV_BGR2RGB);
QImage att_QImageCamera((uchar*) att_MatCamera.data, att_MatCamera.cols, att_MatCamera.rows, att_MatCamera.step, QImage::Format_RGB888);
*att_PixImageCamera = QPixmap::fromImage(att_QImageCamera.scaled(640, 480),Qt::AutoColor);
att_ui->lab_image->setPixmap(*att_PixImageCamera);
}
两个代码几乎是相同的,但我失去了为什么当我启动程序时,没有任何面部检测。它向我展示了一个来自摄像头的视频,但没有面部检测矩形。
有没有人有任何想法?