Home Images are opened differently when changing the Title
Reply: 1

Images are opened differently when changing the Title

CIsForCookies Published in 2018-02-13 15:02:52Z

I'm have a list of image paths I'm opening and showing using this:

    for path in image_paths:
        print 'Path for the this image is: "{}"'.format(path)
        img = cv2.imread(path)

And it opens each image for 250 ms in the center-ish of the screen and moves to next image, as expected. When I change the 1st parameter of cv2.imshow("",img) into cv2.imshow("image {}".format(path[-7:-4]),img) which shuold show the title "image 001", "image XYZ" and so on, the images are opened differntly:

The 1st is opened in the center-ish screen, and the second is opened a bit to the right and to the bottom, and so on, until it reaches some kind of limit and jumps to the upper left corner of some invisible frame. Why is this happening?

karlphillip Reply to 2018-02-13 15:35:39Z

cv2.imshow() displays an image in a window but the first argument (window title) is used to create different windows.

When multiple calls to cv2.imshow() use the same window title, as in:


OpenCV creates a single window (with an empty name) that is reused every time a new image has to be displayed.

On the other hand, calling cv2.imshow("image {}".format(path[-7:-4]), img) in a loop will generate different window titles for every iteration of the loop, which in turn creates a new window on every call. So what you are seeing is the expected behaviour!

If you want several windows to appear at the same place of the screen, simply call cv2.moveWindow() after cv.imshow() with the appropriate screen coordinates:

window_title = "image {}".format(path[-7:-4])
cv2.imshow(window_title, img)
cv2.moveWindow(window_title, 0, 0)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307863 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO