2

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)
2
  • imshow() can display only one image - to display many images you have to use imshow() many times OR you can concatenate all images into one image and then display it. But it would be big image so you would have to resize it to make it smaller. Commented Dec 12, 2019 at 10:23
  • Think twice about loading large numbers of images into lists unnecessarily - they take lots of memory! Maybe you can just hold their names in a list and load them one at a time to display them.... Commented Dec 12, 2019 at 10:23

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.