【问题标题】:How to pass detected faces from a function to a separate push button slot in Qt如何将检测到的人脸从函数传递到 Qt 中的单独按钮槽
【发布时间】:2014-03-20 06:52:02
【问题描述】:

我正在使用 Qt 来创建前端,我有一个名为“facedetect”的方法,因为我可以检测所有的人脸。现在我需要将这些检测到的人脸传递给另一个函数,因为它将检测到的人脸与所有人脸进行比较数据库中的面孔。但实际问题是,当我单击“比较”按钮时,我正在比较面孔(它位于不同的插槽中)。我需要将检测到的面孔访问到“比较”按钮插槽中。 这是我的代码:

void third::facedetect(IplImage* image) //face detection
{
int j=0,l=0,strsize,count=0;
char numstr[50];
CvPoint ul,lr,w,h;
string path;
IplImage* image1;IplImage* tmpsize;IplImage* reimg;
CvHaarClassifierCascade* cascade=(CvHaarClassifierCascade*) cvLoad(cascade_name);                                                      
CvMemStorage* storage=cvCreateMemStorage(0);

if(!cascade)
{
    qDebug()<<"Coulid not load classifier cascade";

}
if(cascade)
{
    CvSeq* faces=cvHaarDetectObjects(image,cascade,storage,1.1,1,CV_HAAR_DO_CANNY_PRUNING,cvSize(10,10));

    for(int i=0;i<(faces ? faces->total : 0);i++)
    {
        string s1="im",re,rename,ex=".jpeg";
        sprintf(numstr, "%d", k);
        re = s1 + numstr;
        rename=re+ex;
        char *extract1=new char[rename.size()+1];
        extract1[rename.size()]=0;
        memcpy(extract1,rename.c_str(),rename.size());
        strsize=rename.size();
        CvRect *r=(CvRect*) cvGetSeqElem(faces,i);
        ul.x=r->x;
        ul.y=r->y;
        w.x=r->width;
        h.y=r->height;
        lr.x=(r->x + r->width);
        lr.y=(r->y + r->height);
        cvSetImageROI(image,cvRect(ul.x,ul.y,w.x,h.y));
        image1=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
        cvCopy(image, image1, NULL);
        reimg=resizeImage(image1, 40, 40, true);
        saveImage(reimg,extract1);
        img_1=cvarrToMat(reimg);//this img_1 contains the detected faces.
        cvResetImageROI(image);
        cvRectangle(image,ul,lr,CV_RGB(1,255,0),3,8,0);
        j++,count++,k++;

    }

}

qDebug()<<"Number of images:"<<count<<endl;
cvNamedWindow("output");//creating a window.
cvShowImage("output",image);//showing resized image.
cvWaitKey(0);//wait for user response.
cvReleaseImage(&image);//releasing the memory.
cvDestroyWindow("output");//destroying the window.
}

**And this the push button 'compare' slot**
void third::on_pushButton_5_clicked()
{

}


If I could access those detected faces from  'void third::on_pushButton_5_clicked()'    then only I can use it in the push button slot'compare'. Please help me to fix this..

【问题讨论】:

    标签: c++ qt opencv image-processing


    【解决方案1】:

    这听起来像是一个声明问题......显示检测到的面部的图像未在“公共”或“全局”变量下声明。如果是这样,那就简单了。

    在你的头文件中,third.h

    class third : public third
    {
        Q_OBJECT
    
    public:
        explicit third(QWidget *parent = 0);
        ~third();
    //declare your image holding the detected face here, which see from your .cpp file is img_1
    

    接下来,对于您的void third::on_pushButton_5_clicked()

    void third::on_pushButton_5_clicked()
    {
             cvNamedWindow("img_1");//creating a window.
             cvShowImage("img_1",img_1);//showing resized image.
             cvWaitKey(0);//wait for user response.
             cvReleaseImage(&img_1);//releasing the memory.
             cvDestroyWindow("img_1");//destroying the window.
    }
    

    代码可能有编译错误,因为我是直接在 stackOverflow 中输入的。

    如果这样可以解决问题,请告诉我,如果可以,请考虑单击箭头下方的勾选按钮并投票。如果它不起作用,请发表评论,我会看看我还能如何提供帮助。干杯!

    【讨论】:

    • 当我尝试这种方法时,我只能访问最后检测到的人脸。我需要访问按钮槽中所有检测到的人脸。然后只有我可以将所有人脸与数据库中的人脸进行比较。
    • 是什么意思,比如我点击检测人脸5次,每5次检测到的人脸图像都会被保存?直到你点击 pushButton_5?
    • 如果你点击facedetect,然后pushButton_5,然后facedetect,然后pushButton_5,那么你提到的情况,不应该发生。
    • 让我知道您在使用哪种方案,或者是否未提及任何一种方案(:
    • 不,当我只单击一次检测面部按钮时,它会检测到所有面部。(通过按向右箭头,我可以看到所有检测到的面部)我还有另一个按钮比较,当我单击它时我需要比较所有的面孔。为此我需要访问所有检测到的面孔。
    猜你喜欢
    • 2012-03-08
    • 2020-01-18
    • 2013-09-24
    • 2020-12-04
    • 2013-10-28
    • 2021-06-27
    • 2019-12-01
    • 2014-05-30
    • 2020-10-15
    相关资源
    最近更新 更多