Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

c - OpenCV: how to force the image window to appear on top of other windows?

Using cvShowImage, one can easily show an image in OpenCV. However, how do you tell OpenCV to show the window on top of every other window?

I run a full screen OpenGL application while showing images. The first time the OpenCV window pops up on top of my application window, but if I click on the window of my application (i.e. give focus back to it), then I can't manage to have the OpenCV come back on top of the OpenGL window, even when destroying and recreating the window.

I thought of renaming the window each time, but is there another way to do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OK, I figured it out which works for both OSX and Windows. You just need to create a full-screen window and show it for a very short time, then your next window from OpenCV will be in front. So, first to open a full-screen window:

cv::namedWindow("GetFocus", CV_WINDOW_NORMAL);
cv::Mat img = cv::Mat::zeros(100, 100, CV_8UC3);
cv::imshow("GetFocus", img);
cv::setWindowProperty("GetFocus", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
waitKey(1);
cv::setWindowProperty("GetFocus", CV_WND_PROP_FULLSCREEN, CV_WINDOW_NORMAL);
destroyWindow("GetFocus");

And then you can open up anther window that actually show the image:

Mat your_image = ...;
cv::namedWindow("ShowImg");
cv::imshow("ShowImg", your_image);

It works for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...