基于QT和OpenCV的人脸检测识别系统

Posted 随波足流

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于QT和OpenCV的人脸检测识别系统相关的知识,希望对你有一定的参考价值。

人脸识别分为两大步骤

1.人脸检测 这个是首要实现的,你得实现人脸显示的时候把人脸框出来,当然算法很多,还有一些人眼检测鼻子检测什么的

主要用的是这个

 const char *faceCascadeFilename = "haarcascade_frontalface_alt.xml";

 detect_and_draw(IplImageBuffer,storage,cascade);

这个函数就是检测人脸的并画框效果如下

主要代码如下

void Chenaini::detect_and_draw(IplImage* img,CvMemStorage* storage, CvHaarClassifierCascade* cascade)

    double scale=1.2;
    static CvScalar colors[] =
        0,0,255,0,128,255,0,255,255,0,255,0,
        255,128,0,255,255,0,255,0,0,255,0,255
    ;//Just some pretty colors to draw with


    IplImage* gray = cvCreateImage(cvSize(img->width,img->height),8,1);
    IplImage* small_img=cvCreateImage(cvSize(cvRound(img->width/scale),cvRound(img->height/scale)),8,1);
    cvCvtColor(img,gray, CV_BGR2GRAY);
    cvResize(gray, small_img, CV_INTER_LINEAR);

    cvEqualizeHist(small_img,small_img);     cvClearMemStorage(storage);
    double t = (double)cvGetTickCount();
        CvSize min=cvSize(0,0);
        CvSize max=cvSize(100,100);
    CvSeq *objects = cvHaarDetectObjects(                               small_img,
                                                                        cascade,storage,
                                                                        1.1,
                                                                       3, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                                                      min,
                                                                      max
                                         );

    t = (double)cvGetTickCount() - t;
    printf( "detection time = %gms\\n", t/((double)cvGetTickFrequency()*1000.) );

    //Loop through found objects and draw boxes around them
    for(int i=0;i<(objects? objects->total:0);++i)
   
        CvRect* r=(CvRect*)cvGetSeqElem(objects,i);
        cvRectangle(img, cvPoint(r->x*scale,r->y*scale), cvPoint((r->x+r->width)*scale,(r->y+r->height)*scale), colors[i%8]);
   
    for( int i = 0; i < (objects? objects->total : 0); i++ )
   
        CvRect* r = (CvRect*)cvGetSeqElem( objects, i );
        CvPoint center;
        int radius;
        center.x = cvRound((r->x + r->width*0.5)*scale);
        center.y = cvRound((r->y + r->height*0.5)*scale);
        radius = cvRound((r->width + r->height)*0.25*scale);
        cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );
   

     QImage image(( uchar*)img->imageData, img->width, img->height, QImage::Format_RGB888);

      ui->label_shipin->clear();
     ui->label_shipin->setScaledContents(true);
      ui->label_shipin->setPixmap(QPixmap::fromImage(image));
      rs = vd->unget_frame();
      cvReleaseImage(&img);

 

 

以上是关于基于QT和OpenCV的人脸检测识别系统的主要内容,如果未能解决你的问题,请参考以下文章

基于QT和OpenCV的人脸识别系统

基于opencv和qt的人脸检测小系统

基于Python+OpenCV实时人脸识别/检测系统(GUI界面)

qt+opencv实现人脸识别打卡系统2.0

基于OpenCV读取摄像头进行人脸检测和人脸识别

基于OpenCv的人脸识别,翻车了居然识别错误。