bugTester.cpp

Minimum working example - Dženan Zukić, 2012-12-14 12:45 pm

Download (1.3 kB)

 
1
#include "opencv2/objdetect/objdetect.hpp"
2
#include "opencv2/imgproc/imgproc.hpp"
3
#include <opencv2/highgui/highgui.hpp>
4
5
using namespace cv;
6
7
int main(int argc, char* argv[])
8
{
9
    CascadeClassifier cascade;
10
    cascade.load("cascade.xml");
11
12
    cv::Mat img = cv::imread("imgUnseen.png",0);
13
14
    int i = 0;
15
    double t = 0;
16
    double xres=0.625, yres=0.625;
17
    vector<Rect> faces;
18
19
    //equalizeHist(img, img);
20
    vector<int> rejectLevels;
21
    vector<double> levelWeights;
22
    t = (double)cvGetTickCount();
23
    cascade.detectMultiScale( img, faces, rejectLevels, levelWeights, 1.1, 4, 0,
24
        Size(20/xres, 20/yres), Size(55/xres, 55/yres), true ); //sizes in mm
25
    t = (double)cvGetTickCount() - t;
26
    printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) );
27
    printf( "detected objects = %d\n", faces.size());
28
    for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++, i++ )
29
    {
30
        Point center;
31
        Scalar color = CV_RGB(255,255,255);
32
        int radius;
33
        center.x = cvRound((r->x + r->width*0.5));
34
        center.y = cvRound((r->y + r->height*0.5));
35
        radius = cvRound((r->width + r->height)*0.25);
36
        circle( img, center, radius, color, 3, 8, 0 );
37
    }
38
    cv::imshow( "result", img );
39
40
    cv::waitKey(0);
41
    return 0;
42
}