cv::setWindowProperty
cv::setWindowProperty
High-level GUI
#include <opencv2/highgui.hpp>
1. setWindowProperty()
void cv::setWindowProperty(const String &winname, int prop_id, double prop_value)
- C++
None = cv.setWindowProperty(winname, prop_id, prop_value)
- Python
Changes parameters of a window dynamically.
动态更改窗口的参数。
The function setWindowProperty
enables changing properties of a window.
函数 setWindowProperty
启用更改窗口的属性。
1.1 Parameters
winname
- Name of the window.
prop_id
- Window property to edit. The supported operation flags are: (cv::WindowPropertyFlags
)
prop_value
- New value of the window property. The supported flags are: (cv::WindowFlags
)
2. WindowPropertyFlags
enum cv::WindowPropertyFlags
Flags for cv::setWindowProperty
/ cv::getWindowProperty
.
2.1 Enumerator
C++: WND_PROP_FULLSCREEN
Python: cv.WND_PROP_FULLSCREEN
fullscreen property (can be WINDOW_NORMAL
or WINDOW_FULLSCREEN
).
C++: WND_PROP_AUTOSIZE
Python: cv.WND_PROP_AUTOSIZE
autosize property (can be WINDOW_NORMAL
or WINDOW_AUTOSIZE
).
C++: WND_PROP_ASPECT_RATIO
Python: cv.WND_PROP_ASPECT_RATIO
window’s aspect ration (can be set to WINDOW_FREERATIO
or WINDOW_KEEPRATIO
).
C++: WND_PROP_OPENGL
Python: cv.WND_PROP_OPENGL
opengl support.
C++: WND_PROP_VISIBLE
Python: cv.WND_PROP_VISIBLE
checks whether the window exists and is visible
检查窗口是否存在并可见
C++: WND_PROP_TOPMOST
Python: cv.WND_PROP_TOPMOST
property to toggle normal window being topmost or not
属性以切换正常窗口是否位于最顶部
3. WindowFlags
enum cv::WindowFlags
Flags for cv::namedWindow
.
3.1 Enumerator
C++: WINDOW_NORMAL
Python: cv.WINDOW_NORMAL
the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
用户可以调整窗口大小 (无限制),也可以将全屏窗口切换为正常大小。
C++: WINDOW_AUTOSIZE
Python: cv.WINDOW_AUTOSIZE
the user cannot resize the window, the size is constrainted by the image displayed.
用户无法调整窗口大小,该大小受所显示图像的限制。
C++: WINDOW_OPENGL
Python: cv.WINDOW_OPENGL
window with opengl support.
C++: WINDOW_FULLSCREEN
Python: cv.WINDOW_FULLSCREEN
change the window to fullscreen.
C++: WINDOW_FREERATIO
Python: cv.WINDOW_FREERATIO
the image expends as much as it can (no ratio constraint).
C++: WINDOW_KEEPRATIO
Python: cv.WINDOW_KEEPRATIO
the ratio of the image is respected.
C++: `WINDOW_GUI_EXPANDED
Python: cv.WINDOW_GUI_EXPANDED
status bar and tool bar
C++: `WINDOW_GUI_NORMAL
Python: cv.WINDOW_GUI_NORMAL
old fashious way
4. Example
//============================================================================
// Name : X11/Xlib.h
// Author : Yongqiang Cheng
// Version : Feb 22, 2020
// Copyright : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat frame;
const char MAIN_WINDOW_NAME[] = "yongqiang";
const bool SCREEN_FULL = true;
//--- INITIALIZE VIDEOCAPTURE
VideoCapture cap;
// open the default camera using default API
// cap.open(0);
// OR advance usage: select any API backend
int deviceID = 0; // 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected API
cap.open(deviceID + apiID);
// check if we succeeded
if (!cap.isOpened())
{
cerr << "ERROR! Unable to open camera\n";
return -1;
}
namedWindow(MAIN_WINDOW_NAME, WINDOW_NORMAL);
setWindowProperty(MAIN_WINDOW_NAME, WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl << "Press any key to terminate" << endl;
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty())
{
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow(MAIN_WINDOW_NAME, frame);
if (waitKey(5) >= 0)
{
break;
}
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}