Created
April 6, 2018 00:32
-
-
Save ardrian/535781f9b063dc81e9387de09f4cfd62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import face_recognition | |
import glob, os | |
def contains_face(filename): | |
image = face_recognition.load_image_file(filename) | |
face_locations = face_recognition.face_locations(image) | |
return len(face_locations) > 0 | |
def main(): | |
if not os.path.isdir("photos_with_faces"): | |
os.mkdir("photos_with_faces") | |
if not os.path.isdir("photos_without_faces"): | |
os.mkdir("photos_without_faces") | |
for file in os.listdir("input_photos"): | |
if file.endswith(".jpg") or file.endswith(".png"): | |
photo_path = os.path.join("input_photos", file) | |
try: | |
face = contains_face(photo_path) | |
if face: | |
os.rename(photo_path,os.path.join("photos_with_faces",file)) | |
else: | |
os.rename(photo_path,os.path.join("photos_without_faces",file)) | |
print("{} contains face? {}".format(photo_path,face)) | |
except: | |
print("Error while reading {}".format(photo_path)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment