Home > Software design >  cv2- display images in same window, one after the other
cv2- display images in same window, one after the other

Time:04-02

Iam trying to display images 1 after the other.

So I want to open image1.png, check it visually, then after clicking any button I want to open image2.png on the same window. Currently, cv2 is closing window of image1 then opening another window in different location in the screen which is confusing.

Any advise?

import cv2
imagespath=['image1.png','image2.png']
for a in imagespath:
    img=cv2.imread(a)
    imgx = cv2.resize(img, (1200, 800))
    x = 0
    while x==0:
        cv2.imshow(a, imgx)#image name same as filename
        cv2.waitKey(0)

CodePudding user response:

You must make a named windows at the beginning, and then use it:

cv2.namedWindow("img", cv2.WINDOW_NORMAL)
# [...]
cv2.imshow("img", imgx)

Edit: Christoph Rackwitz is right, no need to call cv2.namedWindow. It is sufficient to always use the same name of the window.

CodePudding user response:

Change this line

cv2.imshow(a, imgx)#image name same as filename

to

cv2.imshow('pic-display', imgx)

so that the new image gets displayed to the same window named 'pic-display'

  • Related