Suppose I have a number of video clips which are supposed to show a particular sequence of steps but when the clips were created they may have included unwanted action before or after the event.
Would it be possible to use OpenCV to automatically play the video frame by frame so an operator can then hit a key when they see the start of the required action and another when the sequence is finished and have that portion of the video saved as new smaller more accurate video of the sequence.
The code below will read in the webcam frame by frame, flip the frame before writing to a video until the user hits the
qkey on their keyboard.
How would I ensure the user could watch the stream of frames as they come in, then when they see the event they are interested in they can toggle the VideoWriter to start writing those frames to disk but the operator wouldn't need to constantly hit a key to send each frame to the VideoWriter and when the operator sees the event is over they can toggle the VideoWriter off again
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Aucun commentaire:
Enregistrer un commentaire