• 基于QT和OpenCV的人脸检測识别系统(1)


    人脸识别分为两大步骤

    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 ", 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);

    }

  • 相关阅读:
    PostBUILD Event Command Line
    vue 中 $set与$delete的使用
    前端动画必知必会:React 和 Vue 都在用的 FLIP 思想实战
    根据JSON自动构建的vue筛选框组件
    手摸手带你理解Vue的Computed原理
    Flutter开发初探
    实战技巧,Vue原来还可以这样写
    你应该知道的Vue高级特性
    如何去除vue项目中的console内容
    vue: 组件之间传值
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5398422.html
Copyright © 2020-2023  润新知