read images which start with certain string opencv – python

Question:

I have a folder which is containing thousands of images. I want to read only the images which start with a certain string, let’s say input, how can I do this exactly ?

I am using opencv, so this is how I read all images

inputA_path = os.path.join(inputA_dir, '*g')
inputFilesA =glob.glob(inputA_path)

for f1 in inputFilesA:
    inputA = cv2.imread(f1)
Asked By: Mostafa Hussein

||

Answers:

You could just use glob.glob right away and filter for files starting with input and ending with g.

inputFilesA = glob.glob(inputA_dir+"input*g")

for f1 in inputFilesA:
   inputA = cv2.imread(f1)
Answered By: spejsy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.