forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjdetect.go
295 lines (254 loc) · 9.05 KB
/
objdetect.go
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// Package cuda is the GoCV wrapper around OpenCV cuda.
//
// For further details, please see:
// https://github.com/opencv/c
//
// import "gocv.io/x/gocv/cuda"
package cuda
/*
#include <stdlib.h>
#include "../core.h"
#include "objdetect.h"
#include "core.h"
*/
import "C"
import (
"image"
"unsafe"
)
type DescriptorStorageFormat int
const (
DESCR_FORMAT_COL_BY_COL DescriptorStorageFormat = 0
DESCR_FORMAT_COL_BY_ROW DescriptorStorageFormat = 1
)
// CascadeClassifier_GPU is a cascade classifier class for object detection.
//
// For further details, please see:
// https://docs.opencv.org/master/d9/d80/classcv_1_1cuda_1_1CascadeClassifier.html
type CascadeClassifier struct {
p unsafe.Pointer
}
// NewCascadeClassifier_GPU returns a new CascadeClassifier.
func NewCascadeClassifier(name string) CascadeClassifier {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return CascadeClassifier{p: unsafe.Pointer(C.CascadeClassifier_GPU_Create(cName))}
}
// DetectMultiScale detects objects of different sizes in the input Mat image.
// The detected objects are returned as a slice of image.Rectangle structs.
//
// For further details, please see:
// https://docs.opencv.org/master/d9/d80/classcv_1_1cuda_1_1CascadeClassifier.html#a182656b878046eb3f0e9c0f0ee327f08
func (c *CascadeClassifier) DetectMultiScale(img GpuMat) []image.Rectangle {
ret := C.CascadeClassifier_GPU_DetectMultiScale(C.CascadeClassifier_GPU(c.p), img.p)
defer C.GpuRects_Close(ret)
return toRectangles(ret)
}
// HOG is a Histogram Of Gradiants (HOG) for object detection.
//
// For further details, please see:
// https://docs.opencv.org/master/d5/d33/structcv_1_1HOG.html#a723b95b709cfd3f95cf9e616de988fc8
type HOG struct {
p unsafe.Pointer
}
// NewHOG returns a new HOG.
func CreateHOG() HOG {
return HOG{p: unsafe.Pointer(C.HOG_Create())}
}
func CreateHOGWithParams(winSize, blockSize, blockStride, cellSize image.Point, nbins int) HOG {
wSz := C.struct_Size{
width: C.int(winSize.X),
height: C.int(winSize.Y),
}
bSz := C.struct_Size{
width: C.int(blockSize.X),
height: C.int(blockSize.Y),
}
bSt := C.struct_Size{
width: C.int(blockStride.X),
height: C.int(blockStride.Y),
}
cSz := C.struct_Size{
width: C.int(cellSize.X),
height: C.int(cellSize.Y),
}
return HOG{p: unsafe.Pointer(C.HOG_CreateWithParams(wSz, bSz, bSt, cSz, C.int(nbins)))}
}
// Compute returns block descriptors computed for the whole image.
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#ab4287267081959ec77c01269dbfcd373
func (h *HOG) Compute(img GpuMat) GpuMat {
return newGpuMat(C.HOG_Compute(C.HOG(h.p), img.p))
}
// DetectMultiScale detects objects in the input Mat image.
// The detected objects are returned as a slice of image.Rectangle structs.
//
// For further details, please see:
// https://docs.opencv.org/master/d5/d33/structcv_1_1HOG.html#a660e5cd036fd5ddf0f5767b352acd948
func (h *HOG) DetectMultiScale(img GpuMat) []image.Rectangle {
ret := C.HOG_DetectMultiScale(C.HOG(h.p), img.p)
defer C.GpuRects_Close(ret)
return toRectangles(ret)
}
// GetDefaultPeopleDetector returns a new Mat with the HOG DefaultPeopleDetector.
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a016f9ffced8b2f4b20bdd06a775017d1
func (h *HOG) GetDefaultPeopleDetector() C.Mat {
return C.Mat(C.HOG_GetPeopleDetector(C.HOG(h.p)))
}
// SetSVMDetector sets the data for the HOG.
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a5d12db2277b7c3c849d75258eec8d1d4
func (h *HOG) SetSVMDetector(det C.Mat) error {
C.HOG_SetSVMDetector(C.HOG(h.p), det)
return nil
}
// GetDescriptorFormat
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#adad29ed960a953aa13dc59c410683620
func (h *HOG) GetDescriptorFormat() DescriptorStorageFormat {
return DescriptorStorageFormat(C.HOG_GetDescriptorFormat(C.HOG(h.p)))
}
// GetBlockHistogramSize returns the block histogram size.
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a016f9ffced8b2f4b20bdd06a775017d1
func (h *HOG) GetBlockHistogramSize() int {
return int(C.HOG_GetBlockHistogramSize(C.HOG(h.p)))
}
// GetDescriptorFormat returns the number of coefficients required for the classification.
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#adb8c714cba1a025b8869d5a0e152f824
func (h *HOG) GetDescriptorSize() int {
return int(C.HOG_GetDescriptorSize(C.HOG(h.p)))
}
// GetGammaCorrection
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a7032eed27cf7a004b727a6e522c2404e
func (h *HOG) GetGammaCorrection() bool {
return bool(C.HOG_GetGammaCorrection(C.HOG(h.p)))
}
// GetGroupThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a7032eed27cf7a004b727a6e522c2404e
func (h *HOG) GetGroupThreshold() int {
return int(C.HOG_GetGroupThreshold(C.HOG(h.p)))
}
// GetHitThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#ae0de149980ea47fbd39b7766df565b27
func (h *HOG) GetHitThreshold() float64 {
return float64(C.HOG_GetHitThreshold(C.HOG(h.p)))
}
// GetL2HysThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a6853c9a66889fed996678f7972df9660
func (h *HOG) GetL2HysThreshold() float64 {
return float64(C.HOG_GetL2HysThreshold(C.HOG(h.p)))
}
// GetNumLevels
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a15238eb6f52a1ddeedd015773c46efd8
func (h *HOG) GetNumLevels() int {
return int(C.HOG_GetNumLevels(C.HOG(h.p)))
}
// GetScaleFactor
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a89c59564625bb2c691af8c2cf49aab9e
func (h *HOG) GetScaleFactor() float64 {
return float64(C.HOG_GetScaleFactor(C.HOG(h.p)))
}
// GetWinSigma
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a22d03fa05b251b4f19cfa1fab36e754e
func (h *HOG) GetWinSigma() float64 {
return float64(C.HOG_GetWinSigma(C.HOG(h.p)))
}
// GetWinStride
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a6c63504790b51963ca33496a0b039b48
func (h *HOG) GetWinStride() image.Point {
sz := C.HOG_GetWinStride(C.HOG(h.p))
return image.Pt(int(sz.width), int(sz.height))
}
// SetDescriptorFormat
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a6e3e1075a567268f2dfb2151b1c99cb6
func (h *HOG) SetDescriptorFormat(descrFormat DescriptorStorageFormat) {
C.HOG_SetDescriptorFormat(C.HOG(h.p), C.int(descrFormat))
}
// SetGammaCorrection
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a0eb2f1ecf59ccc599bffac3a0a55562f
func (h *HOG) SetGammaCorrection(gammaCorrection bool) {
C.HOG_SetGammaCorrection(C.HOG(h.p), C.bool(gammaCorrection))
}
// SetGroupThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#adad9af4e4ed0e0a045a70cd44520eefd
func (h *HOG) SetGroupThreshold(groupThreshold int) {
C.HOG_SetGroupThreshold(C.HOG(h.p), C.int(groupThreshold))
}
// SetHitThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a8b623393c11d18b89fa373269b97aea4
func (h *HOG) SetHitThreshold(hitThreshold float64) {
C.HOG_SetHitThreshold(C.HOG(h.p), C.double(hitThreshold))
}
// SetL2HysThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a30e5c88864fff774f403313993947d62
func (h *HOG) SetL2HysThreshold(thresholdL2hys float64) {
C.HOG_SetL2HysThreshold(C.HOG(h.p), C.double(thresholdL2hys))
}
// SetNumLevels
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a7602088f3e792de196f8f7efcd9bd448
func (h *HOG) SetNumLevels(nlevels int) {
C.HOG_SetNumLevels(C.HOG(h.p), C.int(nlevels))
}
// SetScaleFactor
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a21dc5e3dc6272030694d52e83352b337
func (h *HOG) SetScaleFactor(scale0 float64) {
C.HOG_SetScaleFactor(C.HOG(h.p), C.double(scale0))
}
// SetWinSigma
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#ab291779ff8ac649174b102f64c5f9012
func (h *HOG) SetWinSigma(winSigma float64) {
C.HOG_SetWinSigma(C.HOG(h.p), C.double(winSigma))
}
// SetWinStride
//
// For further details, please see:
// https://docs.opencv.org/master/de/da6/classcv_1_1cuda_1_1HOG.html#a5e74646651209ae13f1b3dd18179773f
func (h *HOG) SetWinStride(sz image.Point) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.HOG_SetWinStride(C.HOG(h.p), pSize)
return
}