Skip to content

Instantly share code, notes, and snippets.

@sazio
Created August 28, 2020 14:20
Show Gist options
  • Save sazio/dcc32bc68d098af30001bf8f8ebf2bb7 to your computer and use it in GitHub Desktop.
Save sazio/dcc32bc68d098af30001bf8f8ebf2bb7 to your computer and use it in GitHub Desktop.
# return ((x,y,w,h, confidence))
def extract_faces(files, source, detector=detect_face_cv2):
results = []
# for idx, file in tqdm(enumerate(files), total=len(files)):
for idx, file in enumerate(files):
try:
img = cv2.cvtColor(cv2.imread(file, cv2.IMREAD_UNCHANGED), cv2.COLOR_BGR2RGB)
face_locations = detector(img)
results.append((source, file[file.find("output_"):], face_locations, len(face_locations)))
except:
print("Cannot extract faces for image: %s" % file)
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment