forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features2d.go
272 lines (233 loc) · 7.06 KB
/
features2d.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
package gocv
/*
#include <stdlib.h>
#include "features2d.h"
*/
import "C"
import (
"reflect"
"unsafe"
)
// AKAZE is a wrapper around the cv::AKAZE algorithm.
type AKAZE struct {
// C.AKAZE
p unsafe.Pointer
}
// NewAKAZE returns a new AKAZE algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d8/d30/classcv_1_1AKAZE.html
//
func NewAKAZE() AKAZE {
return AKAZE{p: unsafe.Pointer(C.AKAZE_Create())}
}
// Close AKAZE.
func (a *AKAZE) Close() error {
C.AKAZE_Close((C.AKAZE)(a.p))
a.p = nil
return nil
}
// Detect keypoints in an image using AKAZE.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (a *AKAZE) Detect(src Mat) []KeyPoint {
ret := C.AKAZE_Detect((C.AKAZE)(a.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
// Detect keypoints and compute in an image using AKAZE.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677
//
func (a *AKAZE) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) {
desc := NewMat()
ret := C.AKAZE_DetectAndCompute((C.AKAZE)(a.p), src.p, mask.p, desc.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret), desc
}
// AgastFeatureDetector is a wrapper around the cv::AgastFeatureDetector.
type AgastFeatureDetector struct {
// C.AgastFeatureDetector
p unsafe.Pointer
}
// NewAgastFeatureDetector returns a new AgastFeatureDetector algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/d19/classcv_1_1AgastFeatureDetector.html
//
func NewAgastFeatureDetector() AgastFeatureDetector {
return AgastFeatureDetector{p: unsafe.Pointer(C.AgastFeatureDetector_Create())}
}
// Close AgastFeatureDetector.
func (a *AgastFeatureDetector) Close() error {
C.AgastFeatureDetector_Close((C.AgastFeatureDetector)(a.p))
a.p = nil
return nil
}
// Detect keypoints in an image using AgastFeatureDetector.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (a *AgastFeatureDetector) Detect(src Mat) []KeyPoint {
ret := C.AgastFeatureDetector_Detect((C.AgastFeatureDetector)(a.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
// BRISK is a wrapper around the cv::BRISK algorithm.
type BRISK struct {
// C.BRISK
p unsafe.Pointer
}
// NewBRISK returns a new BRISK algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d8/d30/classcv_1_1AKAZE.html
//
func NewBRISK() BRISK {
return BRISK{p: unsafe.Pointer(C.BRISK_Create())}
}
// Close BRISK.
func (b *BRISK) Close() error {
C.BRISK_Close((C.BRISK)(b.p))
b.p = nil
return nil
}
// Detect keypoints in an image using BRISK.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (b *BRISK) Detect(src Mat) []KeyPoint {
ret := C.BRISK_Detect((C.BRISK)(b.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
// Detect keypoints and compute in an image using BRISK.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677
//
func (b *BRISK) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) {
desc := NewMat()
ret := C.BRISK_DetectAndCompute((C.BRISK)(b.p), src.p, mask.p, desc.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret), desc
}
// FastFeatureDetector is a wrapper around the cv::FastFeatureDetector.
type FastFeatureDetector struct {
// C.FastFeatureDetector
p unsafe.Pointer
}
// NewFastFeatureDetector returns a new FastFeatureDetector algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/df/d74/classcv_1_1FastFeatureDetector.html
//
func NewFastFeatureDetector() FastFeatureDetector {
return FastFeatureDetector{p: unsafe.Pointer(C.FastFeatureDetector_Create())}
}
// Close FastFeatureDetector.
func (f *FastFeatureDetector) Close() error {
C.FastFeatureDetector_Close((C.FastFeatureDetector)(f.p))
f.p = nil
return nil
}
// Detect keypoints in an image using FastFeatureDetector.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (f *FastFeatureDetector) Detect(src Mat) []KeyPoint {
ret := C.FastFeatureDetector_Detect((C.FastFeatureDetector)(f.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
// ORB is a wrapper around the cv::ORB.
type ORB struct {
// C.ORB
p unsafe.Pointer
}
// NewORB returns a new ORB algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/d19/classcv_1_1AgastFeatureDetector.html
//
func NewORB() ORB {
return ORB{p: unsafe.Pointer(C.ORB_Create())}
}
// Close ORB.
func (o *ORB) Close() error {
C.ORB_Close((C.ORB)(o.p))
o.p = nil
return nil
}
// Detect keypoints in an image using ORB.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (o *ORB) Detect(src Mat) []KeyPoint {
ret := C.ORB_Detect((C.ORB)(o.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
// Detect keypoints and compute in an image using ORB.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677
//
func (o *ORB) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) {
desc := NewMat()
ret := C.ORB_DetectAndCompute((C.ORB)(o.p), src.p, mask.p, desc.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret), desc
}
// SimpleBlobDetector is a wrapper around the cv::SimpleBlobDetector.
type SimpleBlobDetector struct {
// C.SimpleBlobDetector
p unsafe.Pointer
}
// NewSimpleBlobDetector returns a new SimpleBlobDetector algorithm
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d7a/classcv_1_1SimpleBlobDetector.html
//
func NewSimpleBlobDetector() SimpleBlobDetector {
return SimpleBlobDetector{p: unsafe.Pointer(C.SimpleBlobDetector_Create())}
}
// Close SimpleBlobDetector.
func (b *SimpleBlobDetector) Close() error {
C.SimpleBlobDetector_Close((C.SimpleBlobDetector)(b.p))
b.p = nil
return nil
}
// Detect keypoints in an image using SimpleBlobDetector.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887
//
func (b *SimpleBlobDetector) Detect(src Mat) []KeyPoint {
ret := C.SimpleBlobDetector_Detect((C.SimpleBlobDetector)(b.p), src.p)
defer C.KeyPoints_Close(ret)
return getKeyPoints(ret)
}
func getKeyPoints(ret C.KeyPoints) []KeyPoint {
cArray := ret.keypoints
length := int(ret.length)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cArray)),
Len: length,
Cap: length,
}
s := *(*[]C.KeyPoint)(unsafe.Pointer(&hdr))
keys := make([]KeyPoint, length)
for i, r := range s {
keys[i] = KeyPoint{float64(r.x), float64(r.y), float64(r.size), float64(r.angle), float64(r.response),
int(r.octave), int(r.classID)}
}
return keys
}