学习OpenCV——全屏显示

在播放视频或需要实时展示时,使用全屏的几率很大,OpenCV现在越来越强大已经支持全屏显示,而不需要在程序中再编写Windows函数,使用起来真是十分方便。

主要依靠Qt New Functions:

setWindowProperty(const string& winname, int prop_id, double prop_value) 

Parameters:
  • name – Name of the window.
  • prop_id –

    Window property to edit. The following operation flags are available:

    • CV_WND_PROP_FULLSCREEN Change if the window is fullscreen ( CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN ).
    • CV_WND_PROP_AUTOSIZE Change if the window is resizable (CV_WINDOW_NORMAL or CV_WINDOW_AUTOSIZE ).
    • CV_WND_PROP_ASPECTRATIO Change if the aspect ratio of the image is preserved ( CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO ).
  • prop_value –

    New value of the window property. The following operation flags are available:

    • CV_WINDOW_NORMAL Change the window to normal size or make the window resizable.
    • CV_WINDOW_AUTOSIZE Constrain the size by the displayed image. The window is not resizable.
    • CV_WINDOW_FULLSCREEN Change the window to fullscreen.
    • CV_WINDOW_FREERATIO Make the window resizable without any ratio constraints.
    • CV_WINDOW_KEEPRATIO Make the window resizable, but preserve the proportions of the displayed image.

因此调用全屏,仅仅需要,且不用重新cmake

namedWindow("FullScreen",CV_WINDOW_NORMAL);
setWindowProperty("FullScreen", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN );

Qt New Functions中其他函数:displayOverlay,displayStatusBar,fontQt,addText……


测试程序:

#include <opencv/cv.h>
#include <opencv/highgui.h>

using namespace cv;
using namespace std;

int main()
{
	Mat src = imread("E:/Material/Img/Heads/01.jpg",1);
	imshow("src",src);
	namedWindow("FullScreen",CV_WINDOW_NORMAL);
	setWindowProperty("FullScreen", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN );

	//需要重新编译OpenCV Support Qt
	//displayOverlay("FullScreen","overlay");
	//displayStatusBar("FullScreen","statusBar",10);

	imshow("FullScreen",src);
	waitKey();
}


猜你喜欢

转载自blog.csdn.net/sangni007/article/details/18981267