使用GPU进行OpenCV对象检测

时间:2013-12-27 16:28:58

标签: c++ opencv

因此,对于以下OpenCV教程,我能够编写此代码:

#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main(int argc, const char** argv)
{
    //create the cascade classifier object used for the face detection
    CascadeClassifier face_cascade;
    //use the haarcascade_frontalface_alt.xml library
    face_cascade.load("C:/cascades/haarcascade_frontalface_alt_tree.xml");

    //setup video capture device and link it to the first capture device
    VideoCapture captureDevice;
    captureDevice.open(3);

    //setup image files used in the capture process
    Mat captureFrame;
    Mat grayscaleFrame;

    //create a window to present the results
    namedWindow("outputCapture", 1);

    //create a loop to capture and find faces
    while(true)
    {
        //capture a new image frame
        captureDevice>>captureFrame;

        //convert captured image to gray scale and equalize
        cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
        equalizeHist(grayscaleFrame, grayscaleFrame);

        //create a vector array to store the face found
        std::vector<Rect> faces;

        //find faces and store them in the vector array
        face_cascade.detectMultiScale(grayscaleFrame, faces);

        //draw a rectangle for all found faces in the vector array on the original image
        for(int i = 0; i < (int)faces.size(); i++)
        {
            Scalar color(0, 0, 255);

            Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
            Point pt2(faces[i].x, faces[i].y);

            rectangle(captureFrame, pt1, pt2, color, 1, 8, 0);

            string text = "Adam yuzi";
            int fontFace = FONT_HERSHEY_TRIPLEX;
            double fontScale = 1;
            int thickness = 2;  

            putText(captureFrame, text, pt2, fontFace, fontScale, color, thickness);
            //PlaySound(TEXT("C:/cascades/adam.wav"), NULL, SND_FILENAME | SND_SYNC);// - the correct code
            //Sleep(1000);
            //break;
            //cout<<char(7);
        }

        //print the output
        imshow("outputCapture", captureFrame);

        //pause for 33ms
        waitKey(33);
    }

    return 0;
}

现在我想用GPU改进这段代码的性能。我怎样才能做到这一点?任何代码示例?

0 个答案:

没有答案