From bf04dc3951285589a8990f659860c1020870b893 Mon Sep 17 00:00:00 2001 From: katsunori waragai Date: Sun, 5 Nov 2023 23:52:40 +0900 Subject: [PATCH] use COLOR_BGR2RGB --- examples/blink_detection.py | 14 +++++++------- examples/facerec_from_video_file.py | 2 +- examples/facerec_from_webcam.py | 2 +- examples/facerec_from_webcam_faster.py | 4 ++-- examples/facerec_from_webcam_multiprocessing.py | 2 +- examples/find_faces_in_batches.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/blink_detection.py b/examples/blink_detection.py index bd5bbb624..78774edb2 100644 --- a/examples/blink_detection.py +++ b/examples/blink_detection.py @@ -25,7 +25,7 @@ def main(): ret, frame = video_capture.read(0) # cv2.VideoCapture.release() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) - rgb_small_frame = small_frame[:, :, ::-1] + rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) face_landmarks_list = face_recognition.face_landmarks(rgb_small_frame) process = True @@ -35,12 +35,12 @@ def main(): # get it into the correct format small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) - rgb_small_frame = small_frame[:, :, ::-1] + rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) # get the correct face landmarks - + if process: face_landmarks_list = face_recognition.face_landmarks(rgb_small_frame) @@ -73,7 +73,7 @@ def main(): while (asleep): #continue this loop until they wake up and acknowledge music print("EYES CLOSED") - if cv2.waitKey(1) == 32: #Wait for space key + if cv2.waitKey(1) == 32: #Wait for space key asleep = False print("EYES OPENED") closed_count = 0 @@ -89,14 +89,14 @@ def get_ear(eye): # vertical eye landmarks (x, y)-coordinates A = dist.euclidean(eye[1], eye[5]) B = dist.euclidean(eye[2], eye[4]) - + # compute the euclidean distance between the horizontal # eye landmark (x, y)-coordinates C = dist.euclidean(eye[0], eye[3]) - + # compute the eye aspect ratio ear = (A + B) / (2.0 * C) - + # return the eye aspect ratio return ear diff --git a/examples/facerec_from_video_file.py b/examples/facerec_from_video_file.py index 4c1f4ee93..700d3839f 100644 --- a/examples/facerec_from_video_file.py +++ b/examples/facerec_from_video_file.py @@ -43,7 +43,7 @@ break # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) - rgb_frame = frame[:, :, ::-1] + rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Find all the faces and face encodings in the current frame of video face_locations = face_recognition.face_locations(rgb_frame) diff --git a/examples/facerec_from_webcam.py b/examples/facerec_from_webcam.py index c8dfab2de..a02ed6c5b 100644 --- a/examples/facerec_from_webcam.py +++ b/examples/facerec_from_webcam.py @@ -35,7 +35,7 @@ ret, frame = video_capture.read() # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) - rgb_frame = frame[:, :, ::-1] + rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Find all the faces and face enqcodings in the frame of video face_locations = face_recognition.face_locations(rgb_frame) diff --git a/examples/facerec_from_webcam_faster.py b/examples/facerec_from_webcam_faster.py index e4a7bbd47..1427c2ccf 100644 --- a/examples/facerec_from_webcam_faster.py +++ b/examples/facerec_from_webcam_faster.py @@ -48,8 +48,8 @@ small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) - rgb_small_frame = small_frame[:, :, ::-1] - + rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB) + # Find all the faces and face encodings in the current frame of video face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) diff --git a/examples/facerec_from_webcam_multiprocessing.py b/examples/facerec_from_webcam_multiprocessing.py index a22c31c70..6492d8e5f 100644 --- a/examples/facerec_from_webcam_multiprocessing.py +++ b/examples/facerec_from_webcam_multiprocessing.py @@ -78,7 +78,7 @@ def process(worker_id, read_frame_list, write_frame_list, Global, worker_num): Global.read_num = next_id(Global.read_num, worker_num) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) - rgb_frame = frame_process[:, :, ::-1] + rgb_frame = cv2.cvtColor(frame_process, cv2.COLOR_BGR2RGB) # Find all the faces and face encodings in the frame of video, cost most time face_locations = face_recognition.face_locations(rgb_frame) diff --git a/examples/find_faces_in_batches.py b/examples/find_faces_in_batches.py index dd301498c..933bca3b2 100644 --- a/examples/find_faces_in_batches.py +++ b/examples/find_faces_in_batches.py @@ -29,7 +29,7 @@ break # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) - frame = frame[:, :, ::-1] + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Save each frame of the video to a list frame_count += 1