Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to add loop so that input is automated from a folder instead of specifying individually?

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!")

How to add loop so that input is automated from a folder instead of specifying individually?

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!")

How to add loop so that input is automated from a folder instead of specifying individually?

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!")