比较连续面部检测中的当前和先前面部

时间:2014-03-29 05:29:54

标签: c++ opencv image-processing

我正在使用面部检测。我需要比较当前和之前(连续)面部。任何人都可以帮助我如何从连续面部检测中获取当前和以前的面部。我对此没有任何了解。

这是我的面部检测代码

void facedetect(IplImage* image)
{
ct1++;
cvNamedWindow("output");
int j=0,i,count=0,strsize;
char numstr[50];
CvPoint ul,lr,w,h,ul1,lr1;
CvRect *r;
string path;
IplImage* image1;IplImage* tmpsize;IplImage* reimg;
CvHaarClassifierCascade* cascade=(CvHaarClassifierCascade*) cvLoad(cascade_name);                                                              
CvMemStorage* storage=cvCreateMemStorage(0);
const char *extract;
if(!cascade)
{
    cout<<"Coulid not load classifier cascade"<<endl;

}
if(cascade)
{         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=".pgm";
        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();
        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);
        Mat img=cvarrToMat(reimg);
        //Mat img1=cvarrToMat();
        imshow("result",img); //this is the current image, but i need to get the previous image also.
        //readImag(img,"/home/athira/Image/folderr", path);
        cvResetImageROI(image);
        cvRectangle(image,ul,lr,CV_RGB(1,255,0),3,8,0);
        j++,count++;
        k++;
        arr[l]=ul.x;
        arr1[l]=ul.y;
        cout<<"frame"<<ct1<<" "<<"face"<<ct<<":"<<"x: "<<ul.x<<endl;
        cout<<"frame"<<ct1<<" "<<"face"<<ct<<":"<<"y: "<<ul.y<<endl;
        cout<<""<<endl;
        ct++;
        //compareImages(l,faces->total);
        //feature_extract(img,img1);
        l++;

    }
     width=image->width;
     height=image->height;
     resoltion=width*height;
     s=(float) 0.0301/100;
     diff=s*resoltion;
    cvShowImage("output",image);
    cvWaitKey(0);       
}       
}

0 个答案:

没有答案