如何将检测到的面从函数传递到Qt中的单独按钮插槽

时间:2014-03-20 06:52:03

标签: c++ qt opencv image-processing

我正在使用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..

1 个答案:

答案 0 :(得分:0)

这听起来像是一个声明问题......显示检测到的面部的图像未在&#34; public&#34;或者&#34; global&#34;变量。如果是这样,那很简单。

在您的标头文件中,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.
}

代码可能有complilation错误,因为我直接在stackOverflow中输入它。

如果能解决问题,请告诉我,如果是,请考虑点击箭头下方的勾选按钮并进行提示。如果它没有工作,评论,我会看到我还能提供帮助。干杯!