-
Notifications
You must be signed in to change notification settings - Fork 870
/
aruco.go
337 lines (262 loc) · 12.4 KB
/
aruco.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package gocv
/*
#include <stdlib.h>
#include "aruco.h"
#include "core.h"
*/
import "C"
import (
"reflect"
"unsafe"
)
type ArucoDetector struct {
p C.ArucoDetector
}
// NewArucoDetector returns a new ArucoDetector.
func NewArucoDetector() ArucoDetector {
return ArucoDetector{p: C.ArucoDetector_New()}
}
// NewArucoDetectorWithParams returns a new ArucoDetector.
func NewArucoDetectorWithParams(dictionary ArucoDictionary, params ArucoDetectorParameters) ArucoDetector {
return ArucoDetector{p: C.ArucoDetector_NewWithParams(dictionary.p, params.p)}
}
// Close deletes the ArucoDetector's pointer.
func (a *ArucoDetector) Close() error {
C.ArucoDetector_Close(a.p)
a.p = nil
return nil
}
// DetectMarkers does basic marker detection.
//
// For further details, please see:
// https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa
func (a *ArucoDetector) DetectMarkers(input Mat) (
markerCorners [][]Point2f, markerIds []int, rejectedCandidates [][]Point2f,
) {
pvsCorners := NewPoints2fVector()
defer pvsCorners.Close()
pvsRejected := NewPoints2fVector()
defer pvsRejected.Close()
cmarkerIds := C.IntVector{}
defer C.free(unsafe.Pointer(cmarkerIds.val))
C.ArucoDetector_DetectMarkers(a.p, C.Mat(input.Ptr()), C.Points2fVector(pvsCorners.P()),
&cmarkerIds, C.Points2fVector(pvsRejected.P()))
h := &reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cmarkerIds.val)),
Len: int(cmarkerIds.length),
Cap: int(cmarkerIds.length),
}
pcids := *(*[]C.int)(unsafe.Pointer(h))
markerIds = []int{}
for i := 0; i < int(cmarkerIds.length); i++ {
markerIds = append(markerIds, int(pcids[i]))
}
return pvsCorners.ToPoints(), markerIds, pvsRejected.ToPoints()
}
func ArucoDrawDetectedMarkers(img Mat, markerCorners [][]Point2f, markerIds []int, borderColor Scalar) {
cMarkerIds := make([]C.int, len(markerIds))
for i, s := range markerIds {
cMarkerIds[i] = C.int(s)
}
markerIdsIntVec := C.IntVector{
val: (*C.int)(&cMarkerIds[0]),
length: C.int(len(cMarkerIds)),
}
_markerCorners := NewPoints2fVectorFromPoints(markerCorners)
cBorderColor := C.struct_Scalar{
val1: C.double(borderColor.Val1),
val2: C.double(borderColor.Val2),
val3: C.double(borderColor.Val3),
val4: C.double(borderColor.Val4),
}
C.ArucoDrawDetectedMarkers(
C.Mat(img.Ptr()),
C.Points2fVector(_markerCorners.P()),
markerIdsIntVec,
cBorderColor,
)
}
func ArucoGenerateImageMarker(dictionaryId ArucoDictionaryCode, id int, sidePixels int, img Mat, borderBits int) {
C.ArucoGenerateImageMarker(C.int(dictionaryId), C.int(id), C.int(sidePixels), C.Mat(img.Ptr()), C.int(borderBits))
}
type ArucoDetectorParameters struct {
p C.ArucoDetectorParameters
}
// NewArucoDetectorParameters returns the default parameters for the SimpleBobDetector
func NewArucoDetectorParameters() ArucoDetectorParameters {
return ArucoDetectorParameters{p: C.ArucoDetectorParameters_Create()}
}
func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeMin(adaptiveThreshWinSizeMin int) {
C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeMin(ap.p, C.int(adaptiveThreshWinSizeMin))
}
func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeMin() int {
return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeMin(ap.p))
}
func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeMax(adaptiveThreshWinSizeMax int) {
C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeMax(ap.p, C.int(adaptiveThreshWinSizeMax))
}
func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeMax() int {
return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeMax(ap.p))
}
func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeStep(adaptiveThreshWinSizeStep int) {
C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeStep(ap.p, C.int(adaptiveThreshWinSizeStep))
}
func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeStep() int {
return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeStep(ap.p))
}
func (ap *ArucoDetectorParameters) SetAdaptiveThreshConstant(adaptiveThreshConstant float64) {
C.ArucoDetectorParameters_SetAdaptiveThreshConstant(ap.p, C.double(adaptiveThreshConstant))
}
func (ap *ArucoDetectorParameters) GetAdaptiveThreshConstant() float64 {
return float64(C.ArucoDetectorParameters_GetAdaptiveThreshConstant(ap.p))
}
func (ap *ArucoDetectorParameters) SetMinMarkerPerimeterRate(minMarkerPerimeterRate float64) {
C.ArucoDetectorParameters_SetMinMarkerPerimeterRate(ap.p, C.double(minMarkerPerimeterRate))
}
func (ap *ArucoDetectorParameters) GetMinMarkerPerimeterRate() float64 {
return float64(C.ArucoDetectorParameters_GetMinMarkerPerimeterRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetMaxMarkerPerimeterRate(maxMarkerPerimeterRate float64) {
C.ArucoDetectorParameters_SetMaxMarkerPerimeterRate(ap.p, C.double(maxMarkerPerimeterRate))
}
func (ap *ArucoDetectorParameters) GetMaxMarkerPerimeterRate() float64 {
return float64(C.ArucoDetectorParameters_GetMaxMarkerPerimeterRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetPolygonalApproxAccuracyRate(polygonalApproxAccuracyRate float64) {
C.ArucoDetectorParameters_SetPolygonalApproxAccuracyRate(ap.p, C.double(polygonalApproxAccuracyRate))
}
func (ap *ArucoDetectorParameters) GetPolygonalApproxAccuracyRate() float64 {
return float64(C.ArucoDetectorParameters_GetPolygonalApproxAccuracyRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetMinCornerDistanceRate(minCornerDistanceRate float64) {
C.ArucoDetectorParameters_SetMinCornerDistanceRate(ap.p, C.double(minCornerDistanceRate))
}
func (ap *ArucoDetectorParameters) GetMinCornerDistanceRate() float64 {
return float64(C.ArucoDetectorParameters_GetMinCornerDistanceRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetMinDistanceToBorder(minDistanceToBorder int) {
C.ArucoDetectorParameters_SetMinDistanceToBorder(ap.p, C.int(minDistanceToBorder))
}
func (ap *ArucoDetectorParameters) GetMinDistanceToBorder() int {
return int(C.ArucoDetectorParameters_GetMinDistanceToBorder(ap.p))
}
func (ap *ArucoDetectorParameters) SetMinMarkerDistanceRate(minMarkerDistanceRate float64) {
C.ArucoDetectorParameters_SetMinMarkerDistanceRate(ap.p, C.double(minMarkerDistanceRate))
}
func (ap *ArucoDetectorParameters) GetMinMarkerDistanceRate() float64 {
return float64(C.ArucoDetectorParameters_GetMinMarkerDistanceRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetCornerRefinementMethod(cornerRefinementMethod int) {
C.ArucoDetectorParameters_SetCornerRefinementMethod(ap.p, C.int(cornerRefinementMethod))
}
func (ap *ArucoDetectorParameters) GetCornerRefinementMethod() int {
return int(C.ArucoDetectorParameters_GetCornerRefinementMethod(ap.p))
}
func (ap *ArucoDetectorParameters) SetCornerRefinementWinSize(cornerRefinementWinSize int) {
C.ArucoDetectorParameters_SetCornerRefinementWinSize(ap.p, C.int(cornerRefinementWinSize))
}
func (ap *ArucoDetectorParameters) GetCornerRefinementWinSize() int {
return int(C.ArucoDetectorParameters_GetCornerRefinementWinSize(ap.p))
}
func (ap *ArucoDetectorParameters) SetCornerRefinementMaxIterations(cornerRefinementMaxIterations int) {
C.ArucoDetectorParameters_SetCornerRefinementMaxIterations(ap.p, C.int(cornerRefinementMaxIterations))
}
func (ap *ArucoDetectorParameters) GetCornerRefinementMaxIterations() int {
return int(C.ArucoDetectorParameters_GetCornerRefinementMaxIterations(ap.p))
}
func (ap *ArucoDetectorParameters) SetCornerRefinementMinAccuracy(cornerRefinementMinAccuracy float64) {
C.ArucoDetectorParameters_SetCornerRefinementMinAccuracy(ap.p, C.double(cornerRefinementMinAccuracy))
}
func (ap *ArucoDetectorParameters) GetCornerRefinementMinAccuracy() float64 {
return float64(C.ArucoDetectorParameters_GetCornerRefinementMinAccuracy(ap.p))
}
func (ap *ArucoDetectorParameters) SetMarkerBorderBits(markerBorderBits int) {
C.ArucoDetectorParameters_SetMarkerBorderBits(ap.p, C.int(markerBorderBits))
}
func (ap *ArucoDetectorParameters) GetMarkerBorderBits() int {
return int(C.ArucoDetectorParameters_GetMarkerBorderBits(ap.p))
}
func (ap *ArucoDetectorParameters) SetPerspectiveRemovePixelPerCell(perspectiveRemovePixelPerCell int) {
C.ArucoDetectorParameters_SetPerspectiveRemovePixelPerCell(ap.p, C.int(perspectiveRemovePixelPerCell))
}
func (ap *ArucoDetectorParameters) GetPerspectiveRemovePixelPerCell() int {
return int(C.ArucoDetectorParameters_GetPerspectiveRemovePixelPerCell(ap.p))
}
func (ap *ArucoDetectorParameters) SetPerspectiveRemoveIgnoredMarginPerCell(perspectiveRemoveIgnoredMarginPerCell float64) {
C.ArucoDetectorParameters_SetPerspectiveRemoveIgnoredMarginPerCell(ap.p, C.double(perspectiveRemoveIgnoredMarginPerCell))
}
func (ap *ArucoDetectorParameters) GetPerspectiveRemoveIgnoredMarginPerCell() float64 {
return float64(C.ArucoDetectorParameters_GetPerspectiveRemoveIgnoredMarginPerCell(ap.p))
}
func (ap *ArucoDetectorParameters) SetMaxErroneousBitsInBorderRate(maxErroneousBitsInBorderRate float64) {
C.ArucoDetectorParameters_SetMaxErroneousBitsInBorderRate(ap.p, C.double(maxErroneousBitsInBorderRate))
}
func (ap *ArucoDetectorParameters) GetMaxErroneousBitsInBorderRate() float64 {
return float64(C.ArucoDetectorParameters_GetMaxErroneousBitsInBorderRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetMinOtsuStdDev(minOtsuStdDev float64) {
C.ArucoDetectorParameters_SetMinOtsuStdDev(ap.p, C.double(minOtsuStdDev))
}
func (ap *ArucoDetectorParameters) GetMinOtsuStdDev() float64 {
return float64(C.ArucoDetectorParameters_GetMinOtsuStdDev(ap.p))
}
func (ap *ArucoDetectorParameters) SetErrorCorrectionRate(errorCorrectionRate float64) {
C.ArucoDetectorParameters_SetErrorCorrectionRate(ap.p, C.double(errorCorrectionRate))
}
func (ap *ArucoDetectorParameters) GetErrorCorrectionRate() float64 {
return float64(C.ArucoDetectorParameters_GetErrorCorrectionRate(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagQuadDecimate(aprilTagQuadDecimate float32) {
C.ArucoDetectorParameters_SetAprilTagQuadDecimate(ap.p, C.float(aprilTagQuadDecimate))
}
func (ap *ArucoDetectorParameters) GetAprilTagQuadDecimate() float32 {
return float32(C.ArucoDetectorParameters_GetAprilTagQuadDecimate(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagQuadSigma(aprilTagQuadSigma float32) {
C.ArucoDetectorParameters_SetAprilTagQuadSigma(ap.p, C.float(aprilTagQuadSigma))
}
func (ap *ArucoDetectorParameters) GetAprilTagQuadSigma() float32 {
return float32(C.ArucoDetectorParameters_GetAprilTagQuadSigma(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagMinClusterPixels(aprilTagMinClusterPixels int) {
C.ArucoDetectorParameters_SetAprilTagMinClusterPixels(ap.p, C.int(aprilTagMinClusterPixels))
}
func (ap *ArucoDetectorParameters) GetAprilTagMinClusterPixels() int {
return int(C.ArucoDetectorParameters_GetAprilTagMinClusterPixels(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagMaxNmaxima(aprilTagMaxNmaxima int) {
C.ArucoDetectorParameters_SetAprilTagMaxNmaxima(ap.p, C.int(aprilTagMaxNmaxima))
}
func (ap *ArucoDetectorParameters) GetAprilTagMaxNmaxima() int {
return int(C.ArucoDetectorParameters_GetAprilTagMaxNmaxima(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagCriticalRad(aprilTagCriticalRad float32) {
C.ArucoDetectorParameters_SetAprilTagCriticalRad(ap.p, C.float(aprilTagCriticalRad))
}
func (ap *ArucoDetectorParameters) GetAprilTagCriticalRad() float32 {
return float32(C.ArucoDetectorParameters_GetAprilTagCriticalRad(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagMaxLineFitMse(aprilTagMaxLineFitMse float32) {
C.ArucoDetectorParameters_SetAprilTagMaxLineFitMse(ap.p, C.float(aprilTagMaxLineFitMse))
}
func (ap *ArucoDetectorParameters) GetAprilTagMaxLineFitMse() float32 {
return float32(C.ArucoDetectorParameters_GetAprilTagMaxLineFitMse(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagMinWhiteBlackDiff(aprilTagMinWhiteBlackDiff int) {
C.ArucoDetectorParameters_SetAprilTagMinWhiteBlackDiff(ap.p, C.int(aprilTagMinWhiteBlackDiff))
}
func (ap *ArucoDetectorParameters) GetAprilTagMinWhiteBlackDiff() int {
return int(C.ArucoDetectorParameters_GetAprilTagMinWhiteBlackDiff(ap.p))
}
func (ap *ArucoDetectorParameters) SetAprilTagDeglitch(aprilTagDeglitch int) {
C.ArucoDetectorParameters_SetAprilTagDeglitch(ap.p, C.int(aprilTagDeglitch))
}
func (ap *ArucoDetectorParameters) GetAprilTagDeglitch() int {
return int(C.ArucoDetectorParameters_GetAprilTagDeglitch(ap.p))
}
func (ap *ArucoDetectorParameters) SetDetectInvertedMarker(detectInvertedMarker bool) {
C.ArucoDetectorParameters_SetDetectInvertedMarker(ap.p, C.bool(detectInvertedMarker))
}
func (ap *ArucoDetectorParameters) GetDetectInvertedMarker() bool {
return bool(C.ArucoDetectorParameters_GetDetectInvertedMarker(ap.p))
}