forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgproc.go
263 lines (229 loc) · 10.1 KB
/
imgproc.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
package cuda
/*
#include <stdlib.h>
#include "../core.h"
#include "core.h"
#include "imgproc.h"
*/
import "C"
import (
"unsafe"
"gocv.io/x/gocv"
)
// CannyEdgeDetector
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html
type CannyEdgeDetector struct {
p unsafe.Pointer
}
// NewCannyEdgeDetector returns a new CannyEdgeDetector.
func NewCannyEdgeDetector(lowThresh, highThresh float64) CannyEdgeDetector {
return CannyEdgeDetector{p: unsafe.Pointer(C.CreateCannyEdgeDetector(C.double(lowThresh), C.double(highThresh)))}
}
// NewCannyEdgeDetectorWithParams returns a new CannyEdgeDetector.
func NewCannyEdgeDetectorWithParams(lowThresh, highThresh float64, appertureSize int, L2gradient bool) CannyEdgeDetector {
return CannyEdgeDetector{p: unsafe.Pointer(C.CreateCannyEdgeDetectorWithParams(C.double(lowThresh), C.double(highThresh), C.int(appertureSize), C.bool(L2gradient)))}
}
// Close CannyEdgeDetector
func (h *CannyEdgeDetector) Close() error {
C.CannyEdgeDetector_Close((C.CannyEdgeDetector)(h.p))
h.p = nil
return nil
}
// Detect finds edges in an image using the Canny algorithm.
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a6438cf8453f2dfd6703ceb50056de309
func (h *CannyEdgeDetector) Detect(img GpuMat, dst *GpuMat) {
C.CannyEdgeDetector_Detect(C.CannyEdgeDetector(h.p), img.p, dst.p, nil)
return
}
// DetectWithStream finds edges in an image using the Canny algorithm
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a6438cf8453f2dfd6703ceb50056de309
func (h *CannyEdgeDetector) DetectWithStream(img GpuMat, dst *GpuMat, s Stream) {
C.CannyEdgeDetector_Detect(C.CannyEdgeDetector(h.p), img.p, dst.p, s.p)
return
}
// GetAppertureSize
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a19c2963ff255b0c18387594a704439d3
func (h *CannyEdgeDetector) GetAppertureSize() int {
return int(C.CannyEdgeDetector_GetAppertureSize(C.CannyEdgeDetector(h.p)))
}
// GetHighThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a8366296a57059487dcfd7b30f4a9e3b1
func (h *CannyEdgeDetector) GetHighThreshold() float64 {
return float64(C.CannyEdgeDetector_GetHighThreshold(C.CannyEdgeDetector(h.p)))
}
// GetL2Gradient
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a8fe4ed887c226b12ab44084789b4c6dd
func (h *CannyEdgeDetector) GetL2Gradient() bool {
return bool(C.CannyEdgeDetector_GetL2Gradient(C.CannyEdgeDetector(h.p)))
}
// GetLowThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#aaf5a8944a8ac11093cf7a093b45cd3a8
func (h *CannyEdgeDetector) GetLowThreshold() float64 {
return float64(C.CannyEdgeDetector_GetLowThreshold(C.CannyEdgeDetector(h.p)))
}
// SetAppertureSize
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#aac7d0602338e1a2a783811a929967714
func (h *CannyEdgeDetector) SetAppertureSize(appertureSize int) {
C.CannyEdgeDetector_SetAppertureSize(C.CannyEdgeDetector(h.p), C.int(appertureSize))
}
// SetHighThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a63d352fe7f3bad640e63f4e394619235
func (h *CannyEdgeDetector) SetHighThreshold(highThresh float64) {
C.CannyEdgeDetector_SetHighThreshold(C.CannyEdgeDetector(h.p), C.double(highThresh))
}
// SetL2Gradient
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#ac2e8a675cc30cb3e621ac684e22f89d1
func (h *CannyEdgeDetector) SetL2Gradient(L2gradient bool) {
C.CannyEdgeDetector_SetL2Gradient(C.CannyEdgeDetector(h.p), C.bool(L2gradient))
}
// SetLowThreshold
//
// For further details, please see:
// https://docs.opencv.org/master/d0/d43/classcv_1_1cuda_1_1CannyEdgeDetector.html#a6bdc1479c1557288a69c6314c61d1548
func (h *CannyEdgeDetector) SetLowThreshold(lowThresh float64) {
C.CannyEdgeDetector_SetLowThreshold(C.CannyEdgeDetector(h.p), C.double(lowThresh))
}
// CvtColor converts an image from one color space to another.
// It converts the src Mat image to the dst Mat using the
// code param containing the desired ColorConversionCode color space.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga48d0f208181d5ca370d8ff6b62cbe826
func CvtColor(src GpuMat, dst *GpuMat, code gocv.ColorConversionCode) {
C.GpuCvtColor(src.p, dst.p, C.int(code), nil)
}
// CvtColorWithStream converts an image from one color space to another
// using a Stream for concurrency.
// It converts the src Mat image to the dst Mat using the
// code param containing the desired ColorConversionCode color space.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga48d0f208181d5ca370d8ff6b62cbe826
func CvtColorWithStream(src GpuMat, dst *GpuMat, code gocv.ColorConversionCode, s Stream) {
C.GpuCvtColor(src.p, dst.p, C.int(code), s.p)
}
// HoughLinesDetector
//
// For further details, please see:
// https://docs.opencv.org/master/d2/dcd/classcv_1_1cuda_1_1HoughLinesDetector.html
type HoughLinesDetector struct {
p unsafe.Pointer
}
// NewHoughLinesDetector returns a new HoughLinesDetector.
func NewHoughLinesDetector(rho float32, theta float32, threshold int) HoughLinesDetector {
return HoughLinesDetector{p: unsafe.Pointer(C.HoughLinesDetector_Create(C.double(rho), C.double(theta), C.int(threshold)))}
}
// NewHoughLinesDetectorWithParams returns a new HoughLinesDetector.
func NewHoughLinesDetectorWithParams(rho float32, theta float32, threshold int, sort bool, maxlines int) HoughLinesDetector {
return HoughLinesDetector{p: unsafe.Pointer(C.HoughLinesDetector_CreateWithParams(C.double(rho), C.double(theta), C.int(threshold), C.bool(sort), C.int(maxlines)))}
}
// Close HoughLinesDetector
func (h *HoughLinesDetector) Close() error {
C.HoughLinesDetector_Close((C.HoughLinesDetector)(h.p))
h.p = nil
return nil
}
// Detect finds lines in a binary image using the classical Hough transform.
//
// For further details, please see:
// https://docs.opencv.org/master/d2/dcd/classcv_1_1cuda_1_1HoughLinesDetector.html#a18ff6d0886833ac6215054e191ae2520
func (h *HoughLinesDetector) Detect(img GpuMat, dst *GpuMat) {
C.HoughLinesDetector_Detect(C.HoughLinesDetector(h.p), img.p, dst.p, nil)
return
}
// DetectWithStream finds lines in a binary image using the classical Hough transform
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/d2/dcd/classcv_1_1cuda_1_1HoughLinesDetector.html#a18ff6d0886833ac6215054e191ae2520
func (h *HoughLinesDetector) DetectWithStream(img GpuMat, dst *GpuMat, s Stream) {
C.HoughLinesDetector_Detect(C.HoughLinesDetector(h.p), img.p, dst.p, s.p)
return
}
// HoughSegmentDetector
//
// For further details, please see:
// https://docs.opencv.org/master/d6/df9/classcv_1_1cuda_1_1HoughSegmentDetector.html
type HoughSegmentDetector struct {
p unsafe.Pointer
}
// NewHoughSegmentDetector returns a new HoughSegmentDetector.
func NewHoughSegmentDetector(rho float32, theta float32, minLineLength int, maxLineGap int) HoughSegmentDetector {
return HoughSegmentDetector{p: unsafe.Pointer(C.HoughSegmentDetector_Create(C.double(rho), C.double(theta), C.int(minLineLength), C.int(maxLineGap)))}
}
// Close HoughSegmentDetector
func (h *HoughSegmentDetector) Close() error {
C.HoughSegmentDetector_Close((C.HoughSegmentDetector)(h.p))
h.p = nil
return nil
}
// Detect finds lines in a binary image using the Hough probabilistic transform.
// For further details, please see:
// https://docs.opencv.org/master/d6/df9/classcv_1_1cuda_1_1HoughSegmentDetector.html#a739bf84825ca455966d69dd75ca0ea6e
func (h *HoughSegmentDetector) Detect(img GpuMat, dst *GpuMat) {
C.HoughSegmentDetector_Detect(C.HoughSegmentDetector(h.p), img.p, dst.p, nil)
return
}
// DetectWithStream finds lines in a binary image using the Hough probabilistic transform
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/d6/df9/classcv_1_1cuda_1_1HoughSegmentDetector.html#a739bf84825ca455966d69dd75ca0ea6e
func (h *HoughSegmentDetector) DetectWithStream(img GpuMat, dst *GpuMat, s Stream) {
C.HoughSegmentDetector_Detect(C.HoughSegmentDetector(h.p), img.p, dst.p, s.p)
return
}
// TemplateMatching
//
// For further details, please see:
// https://docs.opencv.org/4.6.0/d2/d58/classcv_1_1cuda_1_1TemplateMatching.html
type TemplateMatching struct {
p unsafe.Pointer
}
// NewTemplateMatching returns a new TemplateMatching.
func NewTemplateMatching(srcType int, method gocv.TemplateMatchMode) TemplateMatching {
return TemplateMatching{p: unsafe.Pointer(C.TemplateMatching_Create(C.int(srcType), C.int(method)))}
}
// Close TemplateMatching
func (tm *TemplateMatching) Close() error {
C.TemplateMatching_Close((C.TemplateMatching)(tm.p))
tm.p = nil
return nil
}
// Match computes a proximity map for a raster template and an image where the template is searched for.
// For further details, please see:
// https://docs.opencv.org/4.6.0/d2/d58/classcv_1_1cuda_1_1TemplateMatching.html#a05a565a53461c916b3b10737cbe43a01
func (tm *TemplateMatching) Match(img GpuMat, tmpl GpuMat, dst *GpuMat) {
C.TemplateMatching_Match(C.TemplateMatching(tm.p), img.p, tmpl.p, dst.p, nil)
return
}
// MatchWithStream computes a proximity map for a raster template and an image where the template is searched for
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/4.6.0/d2/d58/classcv_1_1cuda_1_1TemplateMatching.html#a05a565a53461c916b3b10737cbe43a01
func (tm *TemplateMatching) MatchWithStream(img GpuMat, tmpl GpuMat, dst *GpuMat, s Stream) {
C.TemplateMatching_Match(C.TemplateMatching(tm.p), img.p, tmpl.p, dst.p, s.p)
return
}