-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathopencv_cxcore_cxcore_h.go
435 lines (370 loc) · 12.4 KB
/
opencv_cxcore_cxcore_h.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package opencv
/*
#include "opencv.h"
*/
import "C"
import (
"unsafe"
)
/****************************************************************************************\
* Array allocation, deallocation, initialization and access to elements *
\****************************************************************************************/
func Alloc(size int) unsafe.Pointer {
return unsafe.Pointer(C.cvAlloc(C.size_t(size)))
}
func Free(p unsafe.Pointer) {
C.cvFree_(p)
}
/* Allocates and initializes IplImage header */
func CreateImageHeader(w, h, depth, channels int) *IplImage {
hdr := C.cvCreateImageHeader(
C.cvSize(C.int(w), C.int(h)),
C.int(depth),
C.int(channels),
)
return (*IplImage)(hdr)
}
/* Inializes IplImage header */
func (img *IplImage) InitHeader(w, h, depth, channels, origin, align int) {
C.cvInitImageHeader(
(*C.IplImage)(img),
C.cvSize(C.int(w), C.int(h)),
C.int(depth),
C.int(channels),
C.int(origin),
C.int(align),
)
}
/* Creates IPL image (header and data) */
func CreateImage(w, h, depth, channels int) *IplImage {
size := C.cvSize(C.int(w), C.int(h))
img := C.cvCreateImage(size, C.int(depth), C.int(channels))
return (*IplImage)(img)
}
/* Releases (i.e. deallocates) IPL image header */
func (img *IplImage) ReleaseHeader() {
img_c := (*C.IplImage)(img)
C.cvReleaseImageHeader(&img_c)
}
/* Releases IPL image header and data */
func (img *IplImage) Release() {
img_c := (*C.IplImage)(img)
C.cvReleaseImage(&img_c)
}
/* Creates a copy of IPL image (widthStep may differ) */
func (img *IplImage) Clone() *IplImage {
p := C.cvCloneImage((*C.IplImage)(img))
return (*IplImage)(p)
}
/* Sets a Channel Of Interest (only a few functions support COI) -
use cvCopy to extract the selected channel and/or put it back */
func (img *IplImage) SetCOI(coi int) {
C.cvSetImageCOI((*C.IplImage)(img), C.int(coi))
}
/* Retrieves image Channel Of Interest */
func (img *IplImage) GetCOI() int {
coi := C.cvGetImageCOI((*C.IplImage)(img))
return int(coi)
}
/* Sets image ROI (region of interest) (COI is not changed) */
func (img *IplImage) SetROI(rect Rect) {
C.cvSetImageROI((*C.IplImage)(img), C.CvRect(rect))
}
/* Resets image ROI and COI */
func (img *IplImage) ResetROI() {
C.cvResetImageROI((*C.IplImage)(img))
}
/* Retrieves image ROI */
func (img *IplImage) GetROI() Rect {
r := C.cvGetImageROI((*C.IplImage)(img))
return Rect(r)
}
// mat step
const (
CV_AUTOSTEP = C.CV_AUTOSTEP
)
/* Allocates and initalizes CvMat header */
func CreateMatHeader(rows, cols, type_ int) *Mat {
mat := C.cvCreateMatHeader(
C.int(rows), C.int(cols), C.int(type_),
)
return (*Mat)(mat)
}
/* Allocates and initializes CvMat header and allocates data */
func CreateMat(rows, cols, type_ int) *Mat {
mat := C.cvCreateMat(
C.int(rows), C.int(cols), C.int(type_),
)
return (*Mat)(mat)
}
/* Initializes CvMat header */
func (mat *Mat) InitHeader(rows, cols, type_ int, data unsafe.Pointer, step int) {
C.cvInitMatHeader(
(*C.CvMat)(mat),
C.int(rows),
C.int(cols),
C.int(type_),
data,
C.int(step),
)
}
/* Releases CvMat header and deallocates matrix data
(reference counting is used for data) */
func (mat *Mat) Release() {
mat_c := (*C.CvMat)(mat)
C.cvReleaseMat(&mat_c)
}
/* Decrements CvMat data reference counter and deallocates the data if
it reaches 0 */
func DecRefData(arr *CvArr) {
C.cvDecRefData(unsafe.Pointer(arr))
}
/* Increments CvMat data reference counter */
func IncRefData(arr *CvArr) {
C.cvIncRefData(unsafe.Pointer(arr))
}
/* Creates an exact copy of the input matrix (except, may be, step value) */
func (mat *Mat) Clone() *Mat {
mat_new := C.cvCloneMat((*C.CvMat)(mat))
return (*Mat)(mat_new)
}
/* Makes a new matrix from <rect> subrectangle of input array.
No data is copied */
func GetSubRect(arr *CvArr, submat *Mat, rect Rect) *Mat {
mat_new := C.cvGetSubRect(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
(C.CvRect)(rect),
)
return (*Mat)(mat_new)
}
//#define cvGetSubArr cvGetSubRect
/* Selects row span of the input array: arr(start_row:delta_row:end_row,:)
(end_row is not included into the span). */
func GetRows(arr *CvArr, submat *Mat, start_row, end_row, delta_row int) *Mat {
mat_new := C.cvGetRows(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
C.int(start_row),
C.int(end_row),
C.int(delta_row),
)
return (*Mat)(mat_new)
}
func GetRow(arr *CvArr, submat *Mat, row int) *Mat {
mat_new := C.cvGetRow(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
C.int(row),
)
return (*Mat)(mat_new)
}
/* Selects column span of the input array: arr(:,start_col:end_col)
(end_col is not included into the span) */
func GetCols(arr *CvArr, submat *Mat, start_col, end_col int) *Mat {
mat_new := C.cvGetCols(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
C.int(start_col),
C.int(end_col),
)
return (*Mat)(mat_new)
}
func GetCol(arr *CvArr, submat *Mat, col int) *Mat {
mat_new := C.cvGetCol(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
C.int(col),
)
return (*Mat)(mat_new)
}
/* Select a diagonal of the input array.
(diag = 0 means the main diagonal, >0 means a diagonal above the main one,
<0 - below the main one).
The diagonal will be represented as a column (nx1 matrix). */
func GetDiag(arr *CvArr, submat *Mat, diag int) *Mat {
mat_new := C.cvGetDiag(
unsafe.Pointer(arr),
(*C.CvMat)(submat),
C.int(diag),
)
return (*Mat)(mat_new)
}
/* low-level scalar <-> raw data conversion functions */
func ScalarToRawData(scalar *Scalar, data unsafe.Pointer, type_, extend_to_12 int) {
C.cvScalarToRawData(
(*C.CvScalar)(scalar),
data,
C.int(type_),
C.int(extend_to_12),
)
}
func RawDataToScalar(data unsafe.Pointer, type_ int, scalar *Scalar) {
C.cvRawDataToScalar(
data,
C.int(type_),
(*C.CvScalar)(scalar),
)
}
/* Allocates and initializes CvMatND header */
func CreateMatNDHeader(sizes []int, type_ int) *MatND {
dims := C.int(len(sizes))
sizes_c := make([]C.int, len(sizes))
for i := 0; i < len(sizes); i++ {
sizes_c[i] = C.int(sizes[i])
}
mat := C.cvCreateMatNDHeader(
dims, (*C.int)(&sizes_c[0]), C.int(type_),
)
return (*MatND)(mat)
}
/* Allocates and initializes CvMatND header and allocates data */
func CreateMatND(sizes []int, type_ int) *MatND {
dims := C.int(len(sizes))
sizes_c := make([]C.int, len(sizes))
for i := 0; i < len(sizes); i++ {
sizes_c[i] = C.int(sizes[i])
}
mat := C.cvCreateMatND(
dims, (*C.int)(&sizes_c[0]), C.int(type_),
)
return (*MatND)(mat)
}
/* Initializes preallocated CvMatND header */
func (mat *MatND) InitMatNDHeader(sizes []int, type_ int, data unsafe.Pointer) {
dims := C.int(len(sizes))
sizes_c := make([]C.int, len(sizes))
for i := 0; i < len(sizes); i++ {
sizes_c[i] = C.int(sizes[i])
}
C.cvInitMatNDHeader(
(*C.CvMatND)(mat),
dims, (*C.int)(&sizes_c[0]), C.int(type_),
data,
)
}
/* Releases CvMatND */
func (mat *MatND) Release() {
mat_c := (*C.CvMatND)(mat)
C.cvReleaseMatND(&mat_c)
}
/* Creates a copy of CvMatND (except, may be, steps) */
func (mat *MatND) Clone() *MatND {
mat_c := (*C.CvMatND)(mat)
mat_ret := C.cvCloneMatND(mat_c)
return (*MatND)(mat_ret)
}
/* Allocates and initializes CvSparseMat header and allocates data */
func CreateSparseMat(sizes []int, type_ int) *SparseMat {
dims := C.int(len(sizes))
sizes_c := make([]C.int, len(sizes))
for i := 0; i < len(sizes); i++ {
sizes_c[i] = C.int(sizes[i])
}
mat := C.cvCreateSparseMat(
dims, (*C.int)(&sizes_c[0]), C.int(type_),
)
return (*SparseMat)(mat)
}
/* Releases CvSparseMat */
func (mat *SparseMat) Release() {
mat_c := (*C.CvSparseMat)(mat)
C.cvReleaseSparseMat(&mat_c)
}
/* Creates a copy of CvSparseMat (except, may be, zero items) */
func (mat *SparseMat) Clone() *SparseMat {
mat_c := (*C.CvSparseMat)(mat)
mat_ret := C.cvCloneSparseMat(mat_c)
return (*SparseMat)(mat_ret)
}
/* Initializes sparse array iterator
(returns the first node or NULL if the array is empty) */
func (mat *SparseMat) InitSparseMatIterator(iter *SparseMatIterator) *SparseNode {
mat_c := (*C.CvSparseMat)(mat)
node := C.cvInitSparseMatIterator(mat_c, (*C.CvSparseMatIterator)(iter))
return (*SparseNode)(node)
}
// returns next sparse array node (or NULL if there is no more nodes)
func (iter *SparseMatIterator) Next() *SparseNode {
node := C.cvGetNextSparseNode((*C.CvSparseMatIterator)(iter))
return (*SparseNode)(node)
}
/******** matrix iterator: used for n-ary operations on dense arrays *********/
// P290
/* Returns width and height of array in elements */
func GetSizeWidth(img *IplImage) int {
size := C.cvGetSize(unsafe.Pointer(img))
w := int(size.width)
return w
}
func GetSizeHeight(img *IplImage) int {
size := C.cvGetSize(unsafe.Pointer(img))
w := int(size.height)
return w
}
func GetSize(img *IplImage) Size {
sz := C.cvGetSize(unsafe.Pointer(img))
return Size{int(sz.width), int(sz.height)}
}
/* Copies source array to destination array */
func Copy(src, dst, mask *IplImage) {
C.cvCopy(unsafe.Pointer(src), unsafe.Pointer(dst), unsafe.Pointer(mask))
}
//CVAPI(void) cvCopy( const *CvArr* src, *CvArr* dst,
// const *CvArr* mask CV_DEFAULT(NULL) );
/* Clears all the array elements (sets them to 0) */
func Zero(img *IplImage) {
C.cvSetZero(unsafe.Pointer(img))
}
//CVAPI(void) cvSetZero( *CvArr* arr );
//#define cvZero cvSetZero
/****************************************************************************************\
* Arithmetic, logic and comparison operations *
\****************************************************************************************/
/* dst(idx) = ~src(idx) */
func Not(src, dst *IplImage) {
C.cvNot(unsafe.Pointer(src), unsafe.Pointer(dst))
}
//CVAPI(void) cvNot( const *CvArr* src, *CvArr* dst );
/****************************************************************************************\
* Math operations *
\****************************************************************************************/
/****************************************************************************************\
* Matrix operations *
\****************************************************************************************/
/****************************************************************************************\
* Array Statistics *
\****************************************************************************************/
/****************************************************************************************\
* Discrete Linear Transforms and Related Functions *
\****************************************************************************************/
/****************************************************************************************\
* Dynamic data structures *
\****************************************************************************************/
/****************************************************************************************\
* Drawing *
\****************************************************************************************/
/* Draws 4-connected, 8-connected or antialiased line segment connecting two points */
//color Scalar,
func Line(image *IplImage, pt1, pt2 Point, color Scalar, thickness, line_type, shift int) {
C.cvLine(
unsafe.Pointer(image),
C.cvPoint(C.int(pt1.X), C.int(pt1.Y)),
C.cvPoint(C.int(pt2.X), C.int(pt2.Y)),
(C.CvScalar)(color),
C.int(thickness), C.int(line_type), C.int(shift),
)
//Scalar
}
//CVAPI(void) cvLine( *CvArr* img, CvPoint pt1, CvPoint pt2,
// CvScalar color, int thickness CV_DEFAULT(1),
// int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
/****************************************************************************************\
* System functions *
\****************************************************************************************/
/****************************************************************************************\
* Data Persistence *
\****************************************************************************************/