-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
89 lines (69 loc) · 2.03 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/ml.hpp"
#include "opencv2/objdetect.hpp"
#include <iostream>
#include <string>
#include <time.h>
using namespace cv;
using namespace cv::ml;
using namespace std;
void test_trained_detector( String obj_det_filename, String test_dir, String videofilename );
void test_trained_detector( String obj_det_filename, String test_dir, String videofilename )
{
cout << "Testing trained detector..." << endl;
HOGDescriptor hog;
hog.load( obj_det_filename );
vector< String > files;
glob( test_dir, files );
int delay = 0;
VideoCapture cap;
if ( videofilename != "" )
{
if ( videofilename.size() == 1 && isdigit( videofilename[0] ) )
cap.open( videofilename[0] - '0' );
else
cap.open( videofilename );
}
obj_det_filename = "testing " + obj_det_filename;
namedWindow( obj_det_filename, WINDOW_NORMAL );
for( size_t i=0;; i++ )
{
Mat img;
if ( cap.isOpened() )
{
cap >> img;
delay = 1;
}
else if( i < files.size() )
{
img = imread( files[i] );
}
if ( img.empty() )
{
return;
}
vector< Rect > detections;
vector< double > foundWeights;
hog.detectMultiScale( img, detections, foundWeights );
for ( size_t j = 0; j < detections.size(); j++ )
{
Scalar color = Scalar( 0, foundWeights[j] * foundWeights[j] * 200, 0 );
rectangle( img, detections[j], color, img.cols / 400 + 1 );
}
imshow( obj_det_filename, img );
if( waitKey( delay ) == 27 )
{
return;
}
}
}
int main(int argc, char** argv){
string MODEL_NAME = argv[1];
string FILE_NAME = argv[2];
// string MODEL_NAME = "./my_detector.yml";
// string FILE_NAME = "./Video_1.avi";
string FILE_DIR = "";
test_trained_detector(MODEL_NAME, FILE_DIR, FILE_NAME);
return 0;
}