人脸跟踪C ++的Fps低

时间:2019-06-13 17:24:45

标签: c++ opencv

我已经编写了这段代码来跟踪人的脸,但是,我的fps却很低。当我只做视频时,我的fps更高。

我尝试更改分辨率,但这没用。

#include "opencv2/core.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/objdetect.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;
using namespace std;
int main(int argv, char** argc)
{

    CascadeClassifier faceCascade;
    faceCascade.load("C:\\Users\\farha\\OneDrive\\Desktop\\OpenCV4\\OpenCv\\install\\etc\\haarcascades\\haarcascade_frontalface_alt_tree.xml");

    Mat frame;
    Mat frameGray;
    VideoCapture cap(0);

    while (1)
    {
        cap >> frame;
        cvtColor(frame, frameGray, COLOR_RGB2GRAY);
        vector<Rect> faces;
        faceCascade.detectMultiScale(frame, faces);
        for (int i = 0; i < faces.size(); i++)
        {
            //int x1 = faces[i].x;
            //int y1 = faces[i].y;
            Point pt1(faces[i].x, faces[i].y);
            Point pt2(faces[i].x + faces[i].width, faces[i].height + faces[i].y);//, (faces[i].y, faces[i].width)
            rectangle(frame, pt1, pt2, Scalar(0, 0, 255), 2, 8, 0);

        }
        waitKey(1);
        imshow("Window", frame);
    }
    return 0;
}

0 个答案:

没有答案