【问题标题】:cvSetImageROI to detect eyescvSetImageROI 检测眼睛
【发布时间】:2015-08-26 20:18:21
【问题描述】:

在下面的代码中,我试图检测面部和眼睛。从一个视频。 我的问题是我正在尝试设置 ROI 来检测 eye 。但我认为 cvSetImageROI 函数有错误。

显示此错误

错误 C2664:“cvSetImageROI”:无法将参数 1 从“cv::Mat”转换为“IplImage *”

谢谢你帮助我

#include<stdio.h>
#include<math.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv2\objdetect\objdetect.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<vector>

using namespace cv;
using namespace std;

 int main()
{
CascadeClassifier face_cascade, eye_cascade;
if(!face_cascade.load("haarcascade_frontalface_alt2.xml")) {
    printf("Error loading cascade file for face");
    return 1;
}
if(!eye_cascade.load("haarcascade_eye.xml")) {
    printf("Error loading cascade file for eye");
    return 1;
}
VideoCapture capture("w.mp4"); //-1, 0, 1 device id
if(!capture.isOpened())
{
    printf("error to initialize camera");
    return 1;
}
Mat cap_img,gray_img;
vector<Rect> faces, eyes;
while(1)
{
    capture >> cap_img;
    waitKey(10);
    cvtColor(cap_img, gray_img, CV_BGR2GRAY);
    cv::equalizeHist(gray_img,gray_img);
    face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
    for(int i=0; i < faces.size();i++)
    {
        Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
        Point pt2(faces[i].x,faces[i].y);
        Mat faceROI = gray_img(faces[i]);
        cvSetImageROI(faceROI, cvRect(faces->x,faces->y + (faces->height)/5,faces->width, (faces->height)/3 );
        eye_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30,30));
        for(size_t j=0; j< eyes.size(); j++)
        {
            //Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5, faces[i].y+eyes[j].y+eyes[j].height*0.5);
            Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
            int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
            circle(cap_img, center, radius, Scalar(255,0,0), 2, 8, 0);
        }
        rectangle(cap_img, pt1, pt2, cvScalar(0,255,0), 2, 8, 0);
    }
    imshow("Result", cap_img);
    waitKey(3);
    char c = waitKey(3);
    if(c == 27)
        break;
}
return 0;
}

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    问题是您正在尝试使用旧的 openCV 方法。您的图像采用Mat 格式,cvSetImageROI 不能将Mat 图像作为参数。

    建议:

    Rect region_of_interest = Rect(x, y, w, h);
    Mat image_roi = image(region_of_interest);
    

    【讨论】:

    • 如何在 Rect (x,y,w,h) 中分配眼睛区域
    • 我已从您的代码中获取它:faces-&gt;x,faces-&gt;y + (faces-&gt;height)/5,faces-&gt;width, (faces-&gt;height)/3。你只需要在Rect( -,-,-,- );里面写同样的东西
    • 我将参数应用为 aces->x,faces->y(faces->height)/5,faces->width(faces->height)/3 此错误显示为 'std: :vector<_ty>' 没有重载成员 'operator ->
    • @sarmad:你问到由于使用cvSetImageROI ()而出现错误。答案是关于那个问题。请说明,您仍然收到该错误吗?并且,您目前的问题究竟是什么?
    • 我已将其更改为 Rect region_of_interest = Rect(faces[i].x,faces[i].y + (faces[i].height)/5,faces[i].width, (面孔[i].height)/3); Mat image_roi = image(region_of_interest);它工作了一段时间,并在 Opencv_test_.exe 中的 0x000007fefcebb3dd 处显示未处理的异常:Microsoft C++ exception: cv::Exception at memory location 0x0017f5c0..
    猜你喜欢
    • 2012-03-20
    • 2012-08-27
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 2013-03-22
    • 2018-10-04
    • 2015-04-23
    • 2019-04-20
    相关资源
    最近更新 更多