forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarping.go
317 lines (271 loc) · 10.7 KB
/
warping.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
package cuda
/*
#include <stdlib.h>
#include "warping.h"
*/
import "C"
import (
"image"
"image/color"
)
// InterpolationFlags are bit flags that control the interpolation algorithm
// that is used.
type InterpolationFlags int
const (
// InterpolationNearestNeighbor is nearest neighbor. (fast but low quality)
InterpolationNearestNeighbor InterpolationFlags = 0
// InterpolationLinear is bilinear interpolation.
InterpolationLinear InterpolationFlags = 1
// InterpolationCubic is bicube interpolation.
InterpolationCubic InterpolationFlags = 2
// InterpolationArea uses pixel area relation. It is preferred for image
// decimation as it gives moire-free results.
InterpolationArea InterpolationFlags = 3
// InterpolationLanczos4 is Lanczos interpolation over 8x8 neighborhood.
InterpolationLanczos4 InterpolationFlags = 4
// InterpolationDefault is an alias for InterpolationLinear.
InterpolationDefault = InterpolationLinear
// InterpolationMax indicates use maximum interpolation.
InterpolationMax InterpolationFlags = 7
)
// BorderType type of border.
type BorderType int
const (
// BorderConstant border type
BorderConstant BorderType = 0
// BorderReplicate border type
BorderReplicate BorderType = 1
// BorderReflect border type
BorderReflect BorderType = 2
// BorderWrap border type
BorderWrap BorderType = 3
// BorderReflect101 border type
BorderReflect101 BorderType = 4
// BorderTransparent border type
BorderTransparent BorderType = 5
// BorderDefault border type
BorderDefault = BorderReflect101
// BorderIsolated border type
BorderIsolated BorderType = 16
)
// Resize resizes an image.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga4f5fa0770d1c9efbadb9be1b92a6452a
func Resize(src GpuMat, dst *GpuMat, sz image.Point, fx, fy float64, interp InterpolationFlags) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaResize(src.p, dst.p, pSize, C.double(fx), C.double(fy), C.int(interp), nil)
}
// ResizeWithStream resizes an image
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga4f5fa0770d1c9efbadb9be1b92a6452a
func ResizeWithStream(src GpuMat, dst *GpuMat, sz image.Point, fx, fy float64, interp InterpolationFlags, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaResize(src.p, dst.p, pSize, C.double(fx), C.double(fy), C.int(interp), s.p)
}
// Rotate rotates an image around the origin (0,0) and then shifts it.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga55d958eceb0f871e04b1be0adc6ef1b5
func Rotate(src GpuMat, dst *GpuMat, sz image.Point, angle, xShift, yShift float64, interp InterpolationFlags) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaRotate(src.p, dst.p, pSize, C.double(angle), C.double(xShift), C.double(yShift), C.int(interp), nil)
}
// RotateWithStream rotates an image around the origin (0,0) and then shifts it
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga55d958eceb0f871e04b1be0adc6ef1b5
func RotateWithStream(src GpuMat, dst *GpuMat, sz image.Point, angle, xShift, yShift float64, interp InterpolationFlags, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaRotate(src.p, dst.p, pSize, C.double(angle), C.double(xShift), C.double(yShift), C.int(interp), s.p)
}
// Remap applies a generic geometrical transformation to an image.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga0ece6c76e8efa3171adb8432d842beb0
func Remap(src GpuMat, dst, xmap, ymap *GpuMat, interpolation InterpolationFlags, borderMode BorderType, borderValue color.RGBA) {
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaRemap(src.p, dst.p, xmap.p, ymap.p, C.int(interpolation), C.int(borderMode), bv, nil)
}
// RemapWithStream applies a generic geometrical transformation to an image
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga0ece6c76e8efa3171adb8432d842beb0
func RemapWithStream(src GpuMat, dst, xmap, ymap *GpuMat, interpolation InterpolationFlags, borderMode BorderType, borderValue color.RGBA, s Stream) {
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaRemap(src.p, dst.p, xmap.p, ymap.p, C.int(interpolation), C.int(borderMode), bv, s.p)
}
// PyrDown blurs an image and downsamples it.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga9c8456de9792d96431e065f407c7a91b
func PyrDown(src GpuMat, dst *GpuMat) {
C.CudaPyrDown(src.p, dst.p, nil)
}
// PyrDownWithStream blurs an image and downsamples it
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga9c8456de9792d96431e065f407c7a91b
func PyrDownWithStream(src GpuMat, dst *GpuMat, s Stream) {
C.CudaPyrDown(src.p, dst.p, s.p)
}
// PyrUp upsamples an image and then blurs it.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga2048da0dfdb9e4a726232c5cef7e5747
func PyrUp(src GpuMat, dst *GpuMat) {
C.CudaPyrUp(src.p, dst.p, nil)
}
// PyrUpWithStream upsamples an image and then blurs it
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga2048da0dfdb9e4a726232c5cef7e5747
func PyrUpWithStream(src GpuMat, dst *GpuMat, s Stream) {
C.CudaPyrUp(src.p, dst.p, s.p)
}
// WarpPerspective applies a perspective transformation to an image.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga7a6cf95065536712de6b155f3440ccff
func WarpPerspective(src GpuMat, dst *GpuMat, m GpuMat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaWarpPerspective(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv, nil)
}
// WarpPerspectiveWithStream applies a perspective transformation to an image
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga7a6cf95065536712de6b155f3440ccff
func WarpPerspectiveWithStream(src GpuMat, dst *GpuMat, m GpuMat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaWarpPerspective(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv, s.p)
}
// WarpAffine applies an affine transformation to an image. For more parameters please check WarpAffineWithParams
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga9e8dd9e73b96bdc8e27d85c0e83f1130
func WarpAffine(src GpuMat, dst *GpuMat, m GpuMat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaWarpAffine(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv, nil)
}
// WarpAffineWithStream applies an affine transformation to an image
// using a Stream for concurrency.
//
// For more parameters please check WarpAffineWithParams
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga9e8dd9e73b96bdc8e27d85c0e83f1130
func WarpAffineWithStream(src GpuMat, dst *GpuMat, m GpuMat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
bv := C.struct_Scalar{
val1: C.double(borderValue.B),
val2: C.double(borderValue.G),
val3: C.double(borderValue.R),
val4: C.double(borderValue.A),
}
C.CudaWarpAffine(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv, s.p)
}
// BuildWarpAffineMaps builds transformation maps for affine transformation.
//
// For further details. please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga63504590a96e4cc702d994281d17bc1c
func BuildWarpAffineMaps(M GpuMat, inverse bool, sz image.Point, xmap, ymap *GpuMat) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaBuildWarpAffineMaps(M.p, C.bool(inverse), pSize, xmap.p, ymap.p, nil)
}
// BuildWarpAffineMapsWithStream builds transformation maps for affine transformation
// using a Stream for concurrency.
//
// For further details. please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga63504590a96e4cc702d994281d17bc1c
func BuildWarpAffineMapsWithStream(M GpuMat, inverse bool, sz image.Point, xmap, ymap *GpuMat, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaBuildWarpAffineMaps(M.p, C.bool(inverse), pSize, xmap.p, ymap.p, s.p)
}
// BuildWarpPerspectiveMaps builds transformation maps for perspective transformation.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga8d16e3003703bd3b89cca98c913ef864
func BuildWarpPerspectiveMaps(M GpuMat, inverse bool, sz image.Point, xmap, ymap *GpuMat) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaBuildWarpPerspectiveMaps(M.p, C.bool(inverse), pSize, xmap.p, ymap.p, nil)
}
// BuildWarpPerspectiveMapsWithStream builds transformation maps for perspective transformation
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/db/d29/group__cudawarping.html#ga8d16e3003703bd3b89cca98c913ef864
func BuildWarpPerspectiveMapsWithStream(M GpuMat, inverse bool, sz image.Point, xmap, ymap *GpuMat, s Stream) {
pSize := C.struct_Size{
width: C.int(sz.X),
height: C.int(sz.Y),
}
C.CudaBuildWarpPerspectiveMaps(M.p, C.bool(inverse), pSize, xmap.p, ymap.p, s.p)
}