/
highgui.go
211 lines (174 loc) · 5.78 KB
/
highgui.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
package gocv
/*
#include <stdlib.h>
#include "highgui.h"
*/
import "C"
import (
"unsafe"
)
// Window is a wrapper around OpenCV's "HighGUI" named windows.
// While OpenCV was designed for use in full-scale applications and can be used
// within functionally rich UI frameworks (such as Qt*, WinForms*, or Cocoa*)
// or without any UI at all, sometimes there it is required to try functionality
// quickly and visualize the results. This is what the HighGUI module has been designed for.
//
// For further details, please see:
// http://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html
//
type Window struct {
name string
open bool
}
// NewWindow creates a new named OpenCV window
//
// For further details, please see:
// http://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b
//
func NewWindow(name string) *Window {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
C.Window_New(cName, 2)
return &Window{name: name, open: true}
}
// Close closes and deletes a named OpenCV Window.
//
// For further details, please see:
// http://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga851ccdd6961022d1d5b4c4f255dbab34
//
func (w *Window) Close() error {
cName := C.CString(w.name)
defer C.free(unsafe.Pointer(cName))
C.Window_Close(cName)
w.open = false
return nil
}
// IsOpen checks to see if the Window seems to be open.
func (w *Window) IsOpen() bool {
return w.open
}
// WindowFlag value for SetWindowProperty / GetWindowProperty.
type WindowFlag float32
const (
WindowNormal WindowFlag = 0
WindowFullscreen = 1
WindowAutosize = 1
WindowFreeRatio = 0x00000100
WindowKeepRatio = 0
)
// WindowPropertyFlag flags for SetWindowProperty / GetWindowProperty.
type WindowPropertyFlag int
const (
// WindowPropertyFullscreen fullscreen property
// (can be WINDOW_NORMAL or WINDOW_FULLSCREEN).
WindowPropertyFullscreen WindowPropertyFlag = 0
// WindowPropertyAutosize is autosize property
// (can be WINDOW_NORMAL or WINDOW_AUTOSIZE).
WindowPropertyAutosize = 1
// WindowPropertyAspectRatio window's aspect ration
// (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO).
WindowPropertyAspectRatio = 2
// WindowPropertyOpenGL opengl support.
WindowPropertyOpenGL = 3
// WindowPropertyVisible or not.
WindowPropertyVisible = 4
)
// SetWindowProperty changes parameters of a window dynamically.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga66e4a6db4d4e06148bcdfe0d70a5df27
//
func (w *Window) SetWindowProperty(flag WindowPropertyFlag, value WindowFlag) {
cName := C.CString(w.name)
defer C.free(unsafe.Pointer(cName))
C.Window_SetWindowProperty(cName, C.int(flag), C.double(value))
}
// IMShow displays an image Mat in the specified window.
// This function should be followed by the WaitKey function which displays
// the image for specified milliseconds. Otherwise, it won't display the image.
//
// For further details, please see:
// http://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563
//
func (w *Window) IMShow(img Mat) {
cName := C.CString(w.name)
defer C.free(unsafe.Pointer(cName))
C.Window_IMShow(cName, img.p)
}
// WaitKey waits for a pressed key.
// This function is the only method in OpenCV's HighGUI that can fetch
// and handle events, so it needs to be called periodically
// for normal event processing
//
// For further details, please see:
// http://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7
//
func WaitKey(delay int) int {
return int(C.Window_WaitKey(C.int(delay)))
}
// Trackbar is a wrapper around OpenCV's "HighGUI" window Trackbars.
type Trackbar struct {
name string
parent *Window
}
// CreateTrackbar creates a trackbar and attaches it to the specified window.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b
//
func (w *Window) CreateTrackbar(name string, max int) *Trackbar {
cName := C.CString(w.name)
defer C.free(unsafe.Pointer(cName))
tName := C.CString(name)
defer C.free(unsafe.Pointer(tName))
C.Trackbar_Create(cName, tName, C.int(max))
return &Trackbar{name: name, parent: w}
}
// GetPos returns the trackbar position.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga122632e9e91b9ec06943472c55d9cda8
//
func (t *Trackbar) GetPos() int {
cName := C.CString(t.parent.name)
defer C.free(unsafe.Pointer(cName))
tName := C.CString(t.name)
defer C.free(unsafe.Pointer(tName))
return int(C.Trackbar_GetPos(cName, tName))
}
// SetPos sets the trackbar position.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga67d73c4c9430f13481fd58410d01bd8d
//
func (t *Trackbar) SetPos(pos int) {
cName := C.CString(t.parent.name)
defer C.free(unsafe.Pointer(cName))
tName := C.CString(t.name)
defer C.free(unsafe.Pointer(tName))
C.Trackbar_SetPos(cName, tName, C.int(pos))
}
// SetMin sets the trackbar minimum position.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#gabe26ffe8d2b60cc678895595a581b7aa
//
func (t *Trackbar) SetMin(pos int) {
cName := C.CString(t.parent.name)
defer C.free(unsafe.Pointer(cName))
tName := C.CString(t.name)
defer C.free(unsafe.Pointer(tName))
C.Trackbar_SetMin(cName, tName, C.int(pos))
}
// SetMax sets the trackbar maximum position.
//
// For further details, please see:
// https://docs.opencv.org/3.3.1/d7/dfc/group__highgui.html#ga7e5437ccba37f1154b65210902fc4480
//
func (t *Trackbar) SetMax(pos int) {
cName := C.CString(t.parent.name)
defer C.free(unsafe.Pointer(cName))
tName := C.CString(t.name)
defer C.free(unsafe.Pointer(tName))
C.Trackbar_SetMax(cName, tName, C.int(pos))
}