简体   繁体   中英

Reading and displaying multiple images in opencv

I'm using this code with python and opencv for displaying about 100 images. But imshow function throws an error.

Here is my code:

    nn=[]
    for j in range (187) :
        nn.append(j+63)


    images =[]
    for i in nn:
        path = "02291G0AR\\"
        n1=cv2.imread(path +"Bi000{}".format(i))
        images.append(n1)

    cv2.imshow(images)

And here is the error:

    imshow() missing required argument 'mat' (pos 2)
  1. You have to visualize one image at a time, while you are passing images which is a list
  2. cv2.imshow() takes as first argument the name of the window

So you should iterate on your loaded images like:

for image in images:
    cv2.imshow('Image', image)
    cv2.waitKey(0)  # Wait for user interaction

You may want to take a look to the python opencv documentation about displaying images here .

You can use the following snippet to montage more than one image:

from imutils import build_montages
im_shape = (129,196)
montage_shape = (7,3)
montages = build_montages(images, im_shape, montage_shape)

im_shape : A tuple containing the width and height of each image in the montage. Here we indicate that all images in the montage will be resized to 129 x 196. Resizing every image in the montage to a fixed size is a requirement so we can properly allocate memory in the resulting NumPy array. Note: Empty space in the montage will be filled with black pixels.

montage_shape : A second tuple, this one specifying the number of columns and rows in the montage. Here we indicate that our montage will have 7 columns (7 images wide) and 3 rows (3 images tall).

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