How to input all images from a folder to a function in python instead of specifying individually? [closed]
I have this function called "analyze_picture". This is called when I specify the image file with path. How to automate this by adding loop so that this analyze_picture function is called for all the images in a folder(path). How to add loop so that every image is given as input to that function?
if (choice == 'y'):
run_loop = True
window_name = "Analyze"
print("Default path is set to data/sample/")
print("Type q or quit to end program")
while run_loop:
path = "./data/sample/"
file_name = input("Specify image file: ")
if file_name == "q":
run_loop = False
else:
path += file_name
if os.path.isfile(path):
analyze_picture(fisher_face_gender, path, window_size=(1280, 720), window_name=window_name)
else:
print("File not found!")
uses the answer given in this post
not an opencv specific problem, but a plain python one. look at how to use e.g.
glob()
.you'll also find several examples here
@LBerger, sorry but I didnnt get you
@berak, why you do this? pls help no, I am naive in python
@mueez , see e.g. here
(but again, a python problem(you need to learn the language!), not an opencv one)
@mueez sorry i read your code and I don't realize that you are using python