mirror of
https://github.com/hybridgroup/gocv
synced 2025-08-25 08:41:04 +08:00
highgui: ability to better control the fullscreen window
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -13,6 +13,10 @@ void Window_IMShow(const char* winname, Mat mat) {
|
||||
cv::imshow(winname, *mat);
|
||||
}
|
||||
|
||||
void Window_SetWindowProperty(const char* winname, int flag, double value) {
|
||||
cv::setWindowProperty(winname, flag, value);
|
||||
}
|
||||
|
||||
int Window_WaitKey(int delay = 0) {
|
||||
return cv::waitKey(delay);
|
||||
}
|
||||
|
48
highgui.go
48
highgui.go
@@ -32,7 +32,7 @@ func NewWindow(name string) *Window {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
C.Window_New(cName, 1)
|
||||
C.Window_New(cName, 2)
|
||||
|
||||
return &Window{name: name, open: true}
|
||||
}
|
||||
@@ -56,6 +56,52 @@ 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.
|
||||
|
@@ -12,6 +12,7 @@ extern "C" {
|
||||
void Window_New(const char* winname, int flags);
|
||||
void Window_Close(const char* winname);
|
||||
void Window_IMShow(const char* winname, Mat mat);
|
||||
void Window_SetWindowProperty(const char* winname, int flag, double value);
|
||||
int Window_WaitKey(int);
|
||||
|
||||
// Trackbar
|
||||
|
@@ -19,6 +19,9 @@ func TestWindow(t *testing.T) {
|
||||
if !window.IsOpen() {
|
||||
t.Error("Window should have been open")
|
||||
}
|
||||
|
||||
window.SetWindowProperty(WindowPropertyFullscreen, WindowFullscreen)
|
||||
|
||||
window.Close()
|
||||
if window.IsOpen() {
|
||||
t.Error("Window should have been closed")
|
||||
|
Reference in New Issue
Block a user