From 2cb4fb5e7079e462d6afe833ad628324bd9502c3 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:29:56 +0100 Subject: [PATCH] finalized changes to ouput ROI frames --- get_frames.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/get_frames.py b/get_frames.py index 25b04fb..4c5df3d 100644 --- a/get_frames.py +++ b/get_frames.py @@ -6,13 +6,13 @@ from PIL import Image # Opens the Video file video = 'my_face.mov' path_to_script = os.path.dirname(os.path.abspath(__file__)) -if os.path.exists(path_to_script + r"\frames_testing") == False: - os.mkdir(path_to_script + r"\frames_testing") +if os.path.exists(path_to_script + r"\frames") == False: + os.mkdir(path_to_script + r"\frames") def get_frames(vid): cap= cv2.VideoCapture(vid) i=0 - while i<10: + while cap.isOpened(): ret, img = cap.read() if ret == False: break @@ -45,18 +45,22 @@ def get_frames(vid): list_eh.append(eh) #rectangle on forhead - fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))] - fy = max(list_ey) + try: + fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))] + fy = max(list_ey) + x1 = x + fx + x2 = x + fx + 100 + y1 = y + fy - 150 + y2 = y + fy - 20 + + imRGB = img[y1:y2, x1:x2] + + cv2.imwrite('frames/frame'+str(i)+'.jpg',imRGB) + except: + print('error on min value of ex') #extra values in x and y in the parameters are adjustements made after manual testing #cv2.rectangle(roi_color, (fx,fy-150),(fx+100,fy-20),(0,127,255),2) - x1 = x + fx - x2 = x + fx + 100 - y1 = y + fy - 150 - y2 = y + fy - 20 - imRGB = img[y1:y2, x1:x2] - - cv2.imwrite('frames_testing/frame'+str(i)+'.jpg',imRGB) i+=1 cap.release()