Skip to content
Advertisement

Python: Image face detection and sorting into face and no face

I am trying to create a sorting system where an image is sorted based on having a face or not. and it doesn’t seem to run quite as expected. after the first image is sorted, the loop stops working and I can’t seem to figure out what is wrong. (I am aware of how inefficient it is). all in all, I would love some pointers as to why it might not be working.

JavaScript

Advertisement

Answer

Your main problem is the paths. Let me take a guess that your python file is in ‘~/face detect’ folder, and that is why the first image is read. Then os.chdir(directory) comes and no more images can be found. I corrected the paths to use folders in a less naive way (the correct way was to use glob but i didn’t want to over complicate the answer). Also notice there is no need to change dir in order to save to it, and the fact i initialized the cv2.CascadeClassifier once outside the loop

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement