• 大小: 10.89MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-09
  • 语言: 其他
  • 标签: OpenCV  

资源简介

详细内容见博客:https://blog.csdn.net/li_wen01/article/details/78369751

资源截图

代码片段和文件信息

#include “opencv2/objdetect.hpp“
#include “opencv2/highgui.hpp“
#include “opencv2/imgproc.hpp“
#include 

using namespace std;
using namespace cv;

#define IMAGE_NAME “01.jpg“

void detectAndDraw( Mat& img CascadeClassifier& cascade
                    CascadeClassifier& nestedCascade
                    double scale bool tryflip );

string cascadeName;

int main( int argc const char** argv )
{
    VideoCapture capture;
    Mat frame image;
    string inputName;
    bool tryflip;
    CascadeClassifier cascade nestedCascade;
    double scale = 1.3;


    if( !cascade.load(“./haarcascade_frontalface_alt2.xml“) )
    {
        cerr << “ERROR: Could not load classifier cascade“ << endl;
        return -1;
    }

    image = imread(IMAGE_NAME 1 );
    if( !image.empty() )
    {
        detectAndDraw( image cascade nestedCascade scale tryflip );
        //waitKey(0);
    }
    
    return 0;
}

void detectAndDraw( Mat& img CascadeClassifier& cascade
                    CascadeClassifier& nestedCascade
                    double scale bool tryflip )
{
    double t = 0;
    vector faces faces2;
    const static Scalar colors[] =
    {
        Scalar(25500)
        Scalar(2551280)
        Scalar(2552550)
        Scalar(02550)
        Scalar(0128255)
        Scalar(0255255)
        Scalar(00255)
        Scalar(2550255)
    };
    Mat gray smallImg;

    cvtColor( img gray COLOR_BGR2GRAY );
    double fx = 1 / scale;
    resize( gray smallImg Size() fx fx INTER_LINEAR );
    equalizeHist( smallImg smallImg );

    t = (double)getTickCount();
    cascade.detectMultiScale( smallImg faces
        1.1 2 0
        //|CASCADE_FIND_BIGGEST_object
        //|CASCADE_DO_ROUGH_SEARCH
        |CASCADE_SCALE_IMAGE
        Size(30 30) );

    t = (double)getTickCount() - t;
    printf( “detection time = %g ms\n“ t*1000/getTickFrequency());
    
for ( size_t i = 0; i < faces.size(); i++ )
    {
        Rect r = faces[i];
#if 0
printf(“face num = %d \n“(int)i);
cout << “矩形左上角的横坐标:“ << r.x << endl;
cout << “矩形左上角的纵坐标:“ << r.y << endl;
cout << “矩形的宽度:“ << r.width << endl; 
cout << “矩形的高度:“ << r.height << endl;  
cout << “矩形的尺寸:“ << r.size() << endl;
cout << “矩形的面积:“ << r.area() << endl;
cout << “矩形左上角的点坐标:“ << r.tl() << endl; 
cout << “矩形右下角的点坐标:“ << r.br() << endl; 
cout << endl << endl;
#endif
if(3600 < r.area())
{
Mat roi= img(Rect(r.x*(scale-0.1) r.y*(scale-0.1) r.width*(scale+0.2)r.height*(scale+0.3)));
Mat img1;
roi.copyTo(img1);
//namedWindow(“gag“1);
imwrite(“Roi.jpg“img1);
//imshow(“face“img1);
}

        Scalar color = colors[i%8];

            rectangle( img cvPoint(cvRound(r.x*(scale)) cvRound(r.y*(scale)))
                       cvPoint(cvRound((r.x + r.width-1)*scale) cvRound((r.y + r.height-1)*scale))
                       color 3 8 0);
        
    }
    //imshow( “result“ img );
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     237750  2018-11-25 12:27  OpenCV\arm_test\001.jpg

     文件       3084  2018-10-19 09:48  OpenCV\arm_test\example.cpp

     文件     601661  2018-10-19 08:51  OpenCV\arm_test\haarcascade_eye_tree_eyeglasses.xml

     文件     540616  2017-10-17 19:00  OpenCV\arm_test\haarcascade_frontalface_alt2.xml

     文件       3153  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cv.h

     文件       2649  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cv.hpp

     文件       2523  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cvaux.h

     文件       2374  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cvaux.hpp

     文件       2176  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cvwimage.h

     文件       2424  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cxcore.h

     文件       2443  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cxcore.hpp

     文件       2257  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cxeigen.hpp

     文件        129  2017-10-18 10:09  OpenCV\arm_test\include\opencv\cxmisc.h

     文件       2226  2017-10-18 10:09  OpenCV\arm_test\include\opencv\highgui.h

     文件       2145  2017-10-18 10:09  OpenCV\arm_test\include\opencv\ml.h

     文件       2369  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\calib3d\calib3d.hpp

     文件      20138  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\calib3d\calib3d_c.h

     文件     122181  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\calib3d.hpp

     文件      15392  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\affine.hpp

     文件      26644  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\base.hpp

     文件        723  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\bufferpool.hpp

     文件       2366  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\core.hpp

     文件     131224  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\core_c.h

     文件       8327  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\block.hpp

     文件      24756  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\border_interpolate.hpp

     文件      15518  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\color.hpp

     文件       3814  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\common.hpp

     文件       4720  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\datamov_utils.hpp

     文件     222523  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\detail\color_detail.hpp

     文件      15400  2017-10-18 10:09  OpenCV\arm_test\include\opencv2\core\cuda\detail\reduce.hpp

............此处省略248个文件信息

评论

共有 条评论