zoukankan      html  css  js  c++  java
  • 4、基于JZ2440之编写测试代码处理(处理图片识别人脸)

    1、代码如下:

    void detectAndDisplay(Mat image)
    {
        CascadeClassifier ccf;      //创建脸部对象
        //ccf.load(xmlPath);           //导入opencv自带检测的文件
        if(!ccf.load(xmlPath))     //导入opencv自带检测的文件
        {
            cout<<"无法加载xml文件"<<endl;
            return 0;
        }    
        cout<<"成功导入opencv自带检测的文件"<<endl;
        vector<Rect> faces;         
        Mat gray;                       
        cvtColor(image,gray,CV_BGR2GRAY);
        imwrite("灰度.jpg", gray);
        cout<<"结束cvtColor"<<endl;
        equalizeHist(gray,gray);
        imwrite("直方图均匀化.jpg", gray);
        cout<<"结束equalizeHist"<<endl;
        ccf.detectMultiScale(gray,faces,1.1,3,0,Size(50,50),Size(500,500));
        cout<<"开始detectMultiScale"<<endl;
        for(vector<Rect>::const_iterator iter=faces.begin();iter!=faces.end();iter++)
        {
            rectangle(image,*iter,Scalar(0,0,255),2,8); //画出脸部矩形
        }
        Mat image1;
        cout<<"开始detectMultiScale111111111"<<endl;
        for(size_t i=0;i<faces.size();i++)
        {
            Point center(faces[i].x + faces[i].width / 2, faces[i].y + faces[i].height / 2);
            image1= image(Rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height));     
        }
        cout<<"开始detectMultiScale1111111112222222222"<<endl;
        //imshow("1",image);
        imwrite("2.jpg", image);
        //imshow("2",image1);
        imwrite("3.jpg", image1);
        //cvWaitKey(0);
        
    }
    
    int main() {
        //VideoPlayer();
        string path="1.jpg";//以检测图片1.jpg为例
        Mat image =imread(path,-1);
        
        //CascadeClassifier a;     //创建脸部对象
        detectAndDisplay(image);// 检测人脸
        return 0;    
    }

    2、编译指令如下:

      arm-linux-g++ video_capture.cpp -I/usr/local/arm/include/opencv -lopencv_objdetect -lopencv_highgui -lopencv_imgproc -lopencv_core -lpthread -lrt -o video_capture

    3、结果如下:

  • 相关阅读:
    Python元类
    Python魔术方法
    Python反射
    Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
    游标使用的简单示例
    C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题
    “一键制作启动u盘失败”的主要原因是什么?
    IE11 不能正常方法网页
    Notepad++的右键菜单
    [datatable]排序时指定某列不可排序
  • 原文地址:https://www.cnblogs.com/liusiluandzhangkun/p/9047357.html
Copyright © 2011-2022 走看看