Brier_98
Brier_98

Reputation: 81

The average image of multiple images

I'm using this code but it dosen't work. could youn tell me what is the problem?

import glob , cv2
import numpy as np
def read_img(img_list , img):
    n=cv2.imread(img)
    img_list.append(n)
    return img_list
path = glob.glob("02291G0AR/*.bmp")
list_ = []
cv_image = [read_img(list_,img) for img in path]
for img in cv_image:
    cv2.imshow('image',img)

and the error is: cv2.imshow('image',img)

TypeError: mat is not a numpy array, neither a scalar

Upvotes: 1

Views: 264

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

I think you'll get on better with something like this:

#!/usr/bin/env python3
import glob , cv2
import numpy as np

# Load an image by name and return as Numpy array
def read_img(name):
    img=cv2.imread(name)
    return img

# Generate list of all image names
names = glob.glob("*.bmp")

# Load all images into list
images = [read_img(name) for name in names]

# Display all images in list
for img in images:
    cv2.imshow('image',img)
    cv2.waitKey()

Upvotes: 1

Related Questions