zoukankan      html  css  js  c++  java
  • Opencv人头跟踪检测

    //-------------------------------------人头检测-------------------------------------

    int main()
    {

        //VideoCapture video("E:\C_VC_code\Text_Photo\feini.flv");
        vector<float>head;
        FILE *read = fopen("detector_TQ.txt", "r");
        if (read == NULL)
        {
            cout << "Error: The file read fail" << endl;
            return -1;
        }
        double data;
        while (fscanf(read, "%lf", &data) != -1)
        {
            head.push_back(data);
        }
        cout << head.size() << endl;

        VideoCapture video(0);
        if (!video.isOpened())
        {
            return 0;
        }
        Mat img, dstimg;
        vector<Rect>found;
        vector<Rect>result;
        Rect r;
        HOGDescriptor hog(Size(48, 48), Size(16, 16), Size(8, 8), Size(8, 8), 9);
        hog.setSVMDetector(head);
        double scalar = 0.5;
        int i, j;
        while (1)
        {
            video >> img;
            resize(img, dstimg, Size(img.cols*scalar, img.rows*scalar), 1, 1, 3);
            hog.detectMultiScale(dstimg, found, 1, cv::Size(8, 8), cv::Size(0, 0), 1.1, 3, false);
            //去除嵌套的矩形
            result.clear();
            for (i = 0; i < found.size(); i++)
            {
                r = found[i];

                for (j = 0; j < found.size(); j++)
                {
                    if (i != j && (r&found[j]) == r)
                    {
                        break;
                    }
                }
                if (j == found.size())
                {
                    result.push_back(r);
                }
            }
            //draw rect
            for (i = 0; i<result.size(); i++)
            {
                r = result[i];
                r.x = r.x/scalar*0.81;
                r.y = r.y/scalar;
                r.width = r.width/scalar*1.7;
                r.height = r.height/scalar*4;
                rectangle(img, r, CV_RGB(0, 255, 0), 2);
            }
            //imshow("video1", dstimg);
            imshow("video", img);
            found.clear();
            if (waitKey(33) == 27)
            {
                imshow("video", img);
                waitKey(0);
                break;
            }
        }
    }
  • 相关阅读:
    我喜欢的女孩有了男友 :(
    两个月后,我又回来了。
    准备辞职,想看看老板知道我要辞职之后的表情。
    已经交了辞职报告,今天下午跟老板谈一谈。
    上班第十天
    一年了,回来看看。
    上班第十一天
    领到了离职通知单
    对上班失去了兴趣
    还没有拿到回家的火车票,惨了啊。
  • 原文地址:https://www.cnblogs.com/mypsq/p/5003416.html
Copyright © 2011-2022 走看看