Open blake-edwards opened 6 years ago
I think you've mixed up the order of variables when extracting data from the array. Instead of this:
face_location_array = face_recognition.face_locations(rgb_frame, model=args['detection_method'])
if face_location_array: # prevent manipulation of null variable
y1 = face_location_array[0][0]
x1 = face_location_array[0][1]
end_coordinate_y = face_location_array[0][2]
end_coordinate_x = face_location_array[0][3]
faces_recognized += 1
print("[%i] Face recognized..." % faces_recognized)
cv2.rectangle(frame, (x1, y1), (end_coordinate_x, end_coordinate_y), (0, 0, 255), 2)
cropped_face = frame[x1:end_coordinate_y, y1:end_coordinate_x]
Try this:
face_location_array = face_recognition.face_locations(rgb_frame, model=args['detection_method'])
if face_location_array: # prevent manipulation of null variable
top, right, bottom, left = face_location_array[0]
faces_recognized += 1
print("[%i] Face recognized..." % faces_recognized)
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cropped_face = frame[top:bottom, left:right]
@ageitgey Thank you very much, it works perfectly! Saved me from more frustrating, inconclusive Google searches.
Description
When getting the location of faces in a live webcam feed I have been trying to crop the image to just display the detected face. However, when I used the rectangle coordinates to perform a crop on the image and save it to the disk, the jpg cannot be opened because it is empty.
Here is a screenshot to show you that drawing a rectangle is working.
What I Did