How can I use imshow to display multiple images in multiple windows?

后端 未结 5 1493
醉酒成梦
醉酒成梦 2021-01-02 06:40

I would like to do something like the following in order to display two images on the screen:

imshow("1", img1);
imshow(\'2\', \'img2\');

5条回答
  •  伪装坚强ぢ
    2021-01-02 07:23

    I ran into the problem of having to create an arbitrary number of openCV windows. I had them stored in a list and couldn't simply loop over it to display them:

    # images is a list of openCV image object
    
    for img in images:
        cv2.imshow('image',i)
    

    This doesn't work for the trivial reason of images requiring a different label, hence this loop would only display the last item in the list.

    That can be solved by using an iterator and python string formatters:

    for i, img in enumerator(images):
        cv2.imshow("Image number {}".format(i), img)
    
    

    Therefore now all images will be displayed since they have been assigned a different label.

提交回复
热议问题