Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Multiple images on a folder in OpenCv (python)

I want to read multiple images on a same folder using opencv (python). To do that do I need to use for loop or while loop with imread funcion? If so, how? please help me...

I want to get images into an array and then processed them one at a time through a loop.

like image 569
Thamasha Avatar asked Oct 27 '15 13:10

Thamasha


People also ask

How do I read multiple images in a folder in python?

At first, we imported the pathlib module from Path. Then we pass the directory/folder inside Path() function and used it . glob('*. png') function to iterate through all the images present in this folder.

How do I put 2 photos on cv2?

You can add two images with the OpenCV function, cv. add(), or simply by the numpy operation res = img1 + img2. Both images should be of same depth and type, or the second image can just be a scalar value.


1 Answers

import glob
import cv2

images = [cv2.imread(file) for file in glob.glob("path/to/files/*.png")]
like image 188
Dr Sokoban Avatar answered Sep 28 '22 09:09

Dr Sokoban