简体   繁体   中英

display multiple OpenCV imshow() windows separately

I have a VS console application that is built using opencv library. I am displaying image using the opencv imshow function. The thing is that all the imshow windows overlap over each other and it is difficult to toggle between them. How can I prevent the overlap and display them separately and toggle between them

The way to go about this programatically, is to call resizeWindow() to define each windows' size and moveWindow() to place them at specific locations in your screen.

void cv::resizeWindow(const string& winname, int width, int height)
void cv::moveWindow(const string& winname, int x, int y)

Although this is a late reply, you may find it useful to call moveWindow() after each imshow() call. A language independent solution is given here.

Example steps :-

  1. call imshow("first image", img1)

  2. call moveWindow("first image", img1, 0, 0) // Default position of window is at col,row == 0,0. So, this line is optional.

  3. call imshow("second image", img2)
  4. set firstImageWidth = width of img1
  5. set mySpacing = 40 //vary this to increase/decrease the gap between the image windows.
  6. call moveWindow("first image", img1, firstImageWidth + mySpacing , 0)

Then, add these lines to prevent output windows from being forever active.

  1. set myTime = 7000 //in milliseconds. Here, 7000 ms == 7 secs to show our image windows.
  2. call waitKey(myTime)
  3. call waitKey(1) //this is a trick. Otherwise, the windows are opened indefinitely.

At the moment, I am using Java SE8 with OpenCV 4.2. The above method works for me. Screenshot of the above example in action. Here is a Java+OpenCV code snippet for the display part:

...
//display image. Using OpenCV HighGui class methods.
String inputWindowName = "This window shows input image";
String outputWindowName = "This window shows output image";

HighGui displayWindow = new HighGui();

displayWindow.imshow(inputWindowName, img1);

displayWindow.imshow(outputWindowName, img2);
displayWindow.moveWindow(outputWindowName, img1.cols()+40, 0);

displayWindow.waitKey(7000);
displayWindow.waitKey(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM