how to load a list of image using cv.imread

asked 2020-01-16 18:50:02 -0600

Allaye gravatar image

i want to load a list of images using cv.imread function

image_path_dir = 'C:\\Python'
images_paths = [join(image_path_dir, imagename) for imagename in ['sna3.jpg', 'sna1.jpg', 'bag5.jpg', 't2.jpg', 's3.jpg','sn2.jpg', 't2.jpg']]

image = cv.imread(image_path_dir)

when i do this i get the below error, i cant also use the glob module too any help please.

TypeError: Expected Ptr<cv::umat> for argument '%s'

edit retag flag offensive close merge delete

Comments

2

You pass image_path_dir, i.e. ''C:\Python', to cv.imread, don`t you?

MaxD gravatar imageMaxD ( 2020-01-16 21:38:20 -0600 )edit
1

Why don't you use this code?

images = [cv.imread(os.path.join(image_path_dir, imagename)) for imagename in ['sna3.jpg', 'sna1.jpg', 'bag5.jpg', 't2.jpg', 's3.jpg','sn2.jpg', 't2.jpg']]
LBerger gravatar imageLBerger ( 2020-01-17 02:34:28 -0600 )edit

Try this:

images_paths = [os.path.join(image_path_dir, imagename) for imagename in ['sna3.jpg', 'sna1.jpg', 'bag5.jpg', 't2.jpg', 's3.jpg','sn2.jpg', 't2.jpg']]

image = cv.imread(image_paths)

It is same as @LBerger.

supra56 gravatar imagesupra56 ( 2020-01-17 09:27:08 -0600 )edit

no, @supra56, imread() cannot use a list of images

berak gravatar imageberak ( 2020-01-18 06:22:18 -0600 )edit

@LBerger how will I get around this problem?

Allaye gravatar imageAllaye ( 2020-01-20 03:51:55 -0600 )edit