extracts ROI frames from video

This commit is contained in:
Loic Delattre 2023-02-06 14:11:59 +01:00
parent f86a111048
commit f95730b96d
1 changed files with 13 additions and 7 deletions

View File

@ -6,14 +6,14 @@ 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") == False:
os.mkdir(path_to_script + r"\frames")
if os.path.exists(path_to_script + r"\frames_testing") == False:
os.mkdir(path_to_script + r"\frames_testing")
def get_frames(vid):
cap= cv2.VideoCapture(vid)
i=0
while(cap.isOpened()):
ret, frame = cap.read()
while i<10:
ret, img = cap.read()
if ret == False:
break
@ -48,12 +48,18 @@ def get_frames(vid):
fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))]
fy = max(list_ey)
#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)
#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
cv2.imwrite('frames/frame'+str(i)+'.jpg',frame)
imRGB = img[y1:y2, x1:x2]
cv2.imwrite('frames_testing/frame'+str(i)+'.jpg',imRGB)
i+=1
cap.release()
cv2.destroyAllWindows()
returnx
return
get_frames(video)