How to input all images from a folder to a function in python instead of specifying individually? [closed]

asked 2018-03-21 02:43:19 -0500

mueez gravatar image

updated 2018-03-21 02:50:52 -0500

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!")
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-03-21 02:49:49.798143

Comments

uses the answer given in this post

LBerger gravatar imageLBerger ( 2018-03-21 02:44:27 -0500 )edit

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

berak gravatar imageberak ( 2018-03-21 02:49:35 -0500 )edit
1

@LBerger, sorry but I didnnt get you

mueez gravatar imagemueez ( 2018-03-21 02:49:53 -0500 )edit

@berak, why you do this? pls help no, I am naive in python

mueez gravatar imagemueez ( 2018-03-21 02:52:13 -0500 )edit

@mueez , see e.g. here

(but again, a python problem(you need to learn the language!), not an opencv one)

berak gravatar imageberak ( 2018-03-21 02:53:42 -0500 )edit

@mueez sorry i read your code and I don't realize that you are using python

LBerger gravatar imageLBerger ( 2018-03-21 03:00:11 -0500 )edit