Ask Your Question
0

How to read a series of images with python using OpenCV?

asked 2016-08-25 23:07:01 -0600

littletom gravatar image

I don't know the way to load multiple images with python using OpenCV's API

edit retag flag offensive close merge delete

Comments

what do you mean, exactly ?

like reading in a whole directory ?

berak gravatar imageberak ( 2016-08-26 00:04:51 -0600 )edit

I mean reading many images at the same time so that I don't need to read them in one by one.Since I have to process these pictures using the same algorithm.

littletom gravatar imagelittletom ( 2016-08-26 00:11:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-08-26 00:49:29 -0600

berak gravatar image

you probably still have to "read" an image somehow, but you can batch-process them like this:

from glob import glob
for fn in glob('*.png'):
     im = cv2.imread(fn)
     #
     # your processing here.

if your images are numbered, like im00004.png you can even abuse the VideoCapture:

cap = cv2.VideoCapture("im%05d.png") #like a printf pattern, leading zeros are important !
while cap.isOpened():
     ret,img = cap.read()
     #
     # your processing here
edit flag offensive delete link more

Comments

2

It works!You're amazing!

littletom gravatar imagelittletom ( 2016-08-26 01:05:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-08-25 23:07:01 -0600

Seen: 10,298 times

Last updated: Aug 26 '16