In Python/opencv Is There A Way To Quickly Scroll Through Frames Of A Video, Allowing The User To Select The Start And End Frame To Be Processed?
In preparing to process a video I want the user to be able to select the first and last frame to be processed in the video. The trackbar seems like a useful tool to do this but ca
Solution 1:
first of all, you can set the video position with:
cap.set(cv2.CAP_PROP_POS_FRAMES,pos)
then it's just putting together the pieces, let them play with the trackbars, when a key was pressed, play the interval:
import cv2
cap = cv2.VideoCapture('david.mpg')
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
def onChange(trackbarValue):
cap.set(cv2.CAP_PROP_POS_FRAMES,trackbarValue)
err,img = cap.read()
cv2.imshow("mywindow", img)
pass
cv2.namedWindow('mywindow')
cv2.createTrackbar( 'start', 'mywindow', 0, length, onChange )
cv2.createTrackbar( 'end' , 'mywindow', 100, length, onChange )
onChange(0)
cv2.waitKey()
start = cv2.getTrackbarPos('start','mywindow')
end = cv2.getTrackbarPos('end','mywindow')
if start >= end:
raise Exception("start must be less than end")
cap.set(cv2.CAP_PROP_POS_FRAMES,start)
while cap.isOpened():
err,img = cap.read()
ifcap.get(cv2.CAP_PROP_POS_FRAMES) >= end:
break
cv2.imshow("mywindow", img)
k = cv2.waitKey(10) & 0xffif k==27:
break
Post a Comment for "In Python/opencv Is There A Way To Quickly Scroll Through Frames Of A Video, Allowing The User To Select The Start And End Frame To Be Processed?"