-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.cpp
executable file
·63 lines (53 loc) · 1.48 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
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "dtdpm.h"
struct Rect {
int x;
int y;
int height;
int width;
};
Matrix<double>* FitObjDetectionData(Rect rect, IplImage* img) {
Matrix<double>* mat = new Matrix<double>();
int dims[3];
dims[0] = rect.height;
dims[1] = rect.width;
dims[2] = 1;
mat->Set(3, dims, 0);
double *tmpData = mat->GetData();
int count = 0;
for ( int i = rect.x; i < rect.x + rect.width; i++ ) {
for ( int j = rect.y ; j < rect.y + rect.height; j++ ) {
tmpData[count] = (unsigned char)img->imageData[j*img->widthStep+i];
count++;
}
}
return mat;
}
int main() {
IplImage* src = cvLoadImage("16.jpg");
IplImage* gray = cvCreateImage(cvGetSize(src), 8, 1);
cvCvtColor(src, gray, CV_BGR2GRAY);
DTDPM* dtdpm = new DTDPM("car.model");
Rect testRect;
testRect.x = testRect.y = 0;
testRect.height = gray->height;
testRect.width = gray->width;
Matrix<double>* mat = FitObjDetectionData(testRect, gray);
_FeatPyramid *pyr = new _FeatPyramid(mat, dtdpm->GetMaxSize(), -1, -1, dtdpm->GetMaxSbin(), dtdpm->GetInterval() );
ObjBox *result;
int pickNum;
dtdpm->CascadeDetect(-0.5, 0.5, pyr, &result, &pickNum);
for (int j = 0; j < pickNum; ++j){
cvRectangle(src, cvPoint(result[j].x1, result[j].y1),
cvPoint(result[j].x2, result[j].y2), \
CV_RGB( 255, 255, 255), 1, 8, 0);
}
cvShowImage("test", src);
cvWaitKey(0);
delete mat;
delete pyr;
delete result;
return 0;
}