【发布时间】: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