forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objdetect.cpp
155 lines (117 loc) · 4.03 KB
/
objdetect.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "../core.h"
#include "cuda.h"
#include "objdetect.h"
// CascadeClassifier_GPU
CascadeClassifier_GPU CascadeClassifier_GPU_Create(const char* cascade_name) {
return new cv::Ptr<cv::cuda::CascadeClassifier>(cv::cuda::CascadeClassifier::create(cascade_name));
}
struct Rects CascadeClassifier_GPU_DetectMultiScale(CascadeClassifier_GPU cs, GpuMat img) {
std::vector<cv::Rect> detected;
cv::cuda::GpuMat objbuf;
(*cs)->detectMultiScale(*img, objbuf); // uses all default parameters
(*cs)->convert(objbuf, detected);
Rect* rects = new Rect[detected.size()];
for (size_t i = 0; i < detected.size(); ++i) {
Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height};
rects[i] = r;
}
Rects ret = {rects, (int)detected.size()};
return ret;
}
// HOG
HOG HOG_Create() {
return new cv::Ptr<cv::cuda::HOG>(cv::cuda::HOG::create());
}
HOG HOG_CreateWithParams(Size winSize, Size blockSize, Size blockStride, Size cellSize, int nbins) {
cv::Size winSz(winSize.width, winSize.height);
cv::Size blockSz(blockSize.width, blockSize.height);
cv::Size blockSt(blockStride.width, blockStride.height);
cv::Size cellSz(cellSize.width, cellSize.height);
return new cv::Ptr<cv::cuda::HOG>(cv::cuda::HOG::create(winSz, blockSz, blockSt, cellSz, nbins));
}
struct Rects HOG_DetectMultiScale(HOG hog, GpuMat img) {
std::vector<cv::Rect> detected;
(*hog)->detectMultiScale(*img, detected);
Rect* rects = new Rect[detected.size()];
for (size_t i = 0; i < detected.size(); ++i) {
Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height};
rects[i] = r;
}
Rects ret = {rects, (int)detected.size()};
return ret;
}
GpuMat HOG_Compute(HOG hog, GpuMat img) {
GpuMat dst = new cv::cuda::GpuMat();
(*hog)->compute(*img, *dst);
return dst;
}
Mat HOG_GetPeopleDetector(HOG hog) {
return new cv::Mat((*hog)->getDefaultPeopleDetector());
}
void HOG_SetSVMDetector(HOG hog, Mat det) {
(*hog)->setSVMDetector(*det);
}
int HOG_GetDescriptorFormat(HOG hog) {
return int((*hog)->getDescriptorFormat());
}
size_t HOG_GetBlockHistogramSize(HOG hog) {
return size_t((*hog)->getBlockHistogramSize());
}
size_t HOG_GetDescriptorSize(HOG hog) {
return size_t((*hog)->getDescriptorSize());
}
bool HOG_GetGammaCorrection(HOG hog) {
return bool((*hog)->getGammaCorrection());
}
int HOG_GetGroupThreshold(HOG hog) {
return int((*hog)->getGroupThreshold());
}
double HOG_GetHitThreshold(HOG hog) {
return double((*hog)->getHitThreshold());
}
double HOG_GetL2HysThreshold(HOG hog) {
return double((*hog)->getL2HysThreshold());
}
int HOG_GetNumLevels(HOG hog) {
return int((*hog)->getNumLevels());
}
double HOG_GetScaleFactor(HOG hog) {
return double((*hog)->getScaleFactor());
}
double HOG_GetWinSigma(HOG hog) {
return double((*hog)->getWinSigma());
}
struct Size HOG_GetWinStride(HOG hog) {
cv::Size sz = (*hog)->getWinStride();
Size size = {sz.width, sz.height};
return size;
}
void HOG_SetDescriptorFormat(HOG hog, int descrFormat) {
auto df = static_cast<cv::HOGDescriptor::DescriptorStorageFormat>(descrFormat);
(*hog)->setDescriptorFormat(df);
}
void HOG_SetGammaCorrection(HOG hog, bool gammaCorrection) {
(*hog)->setGammaCorrection(gammaCorrection);
}
void HOG_SetGroupThreshold(HOG hog, int groupThreshold) {
(*hog)->setGroupThreshold(groupThreshold);
}
void HOG_SetHitThreshold(HOG hog, double hitThreshold) {
(*hog)->setHitThreshold(hitThreshold);
}
void HOG_SetL2HysThreshold(HOG hog, double thresholdL2hys) {
(*hog)->setL2HysThreshold(thresholdL2hys);
}
void HOG_SetNumLevels(HOG hog, int nlevels) {
(*hog)->setNumLevels(nlevels);
}
void HOG_SetScaleFactor(HOG hog, double scale0) {
(*hog)->setScaleFactor(scale0);
}
void HOG_SetWinSigma(HOG hog, double winSigma) {
(*hog)->setWinSigma(winSigma);
}
void HOG_SetWinStride(HOG hog, Size dsize) {
cv::Size sz(dsize.width, dsize.height);
(*hog)->setWinStride(sz);
}