I have 2 video files that 1 want to review frame by frame with 1 trackbar.
Is it possible to show 2 videos in 1 named window and have the trackbar
scroll through the frames of both videos? The videos are sports-motion captures that I want to keep in sync.
Or do I need to create 2 separate named windows and have the trackbar update both positions with
while (cap1.isOpened()):
pos = cv2.getTrackbarPos(trackbar_name, title_window_1)
cap1.set(cv2.CAP_PROP_POS_FRAMES, pos)
cap2.set(cv2.CAP_PROP_POS_FRAMES, pos)
Nevermind, I found I can just combine the 2 frames vertically and use 1 window and trackbar.
def main():
global preview
cap1 = cv2.VideoCapture("raw-swing.mp4")
cap2 = cv2.VideoCapture("annotated-swing.mp4")
trackbar_name = "Frame"
window_name = 'dual-view'
cv2.namedWindow(window_name, cv2.WINDOW_GUI_EXPANDED)
cv2.resizeWindow(window_name, 800, 1300)
cv2.setWindowProperty(window_name, cv2.WND_PROP_AUTOSIZE, cv2.WINDOW_GUI_EXPANDED)
framecount = int(cap1.get(cv2.CAP_PROP_FRAME_COUNT))
cv2.createTrackbar(trackbar_name, window_name, 0, (framecount - 1), onchange)
cv2.setTrackbarMin(trackbar_name,window_name,0)
cv2.setTrackbarMax(trackbar_name,window_name,(framecount - 1))
cv2.setTrackbarPos(trackbar_name,window_name,0)
cv2.setMouseCallback(window_name, onclick)
while(cap1.isOpened() and cap2.isOpened()):
ret1, frame1 = cap1.read()
ret2, frame2 = cap2.read()
pos = cv2.getTrackbarPos(trackbar_name, window_name)
cap1.set(cv2.CAP_PROP_POS_FRAMES, pos)
cap2.set(cv2.CAP_PROP_POS_FRAMES, pos)
vertical_join = cv2.vconcat([frame1, frame2])
cv2.imshow(window_name,vertical_join)
key = cv2.waitKey(1)
if key == 27: # esc key
break
elif key == 2: # Left arrow key
cv2.setTrackbarPos(trackbar_name,window_name,pos-1)
cap1.set(cv2.CAP_PROP_POS_FRAMES, pos-1)
cap2.set(cv2.CAP_PROP_POS_FRAMES, pos-1)
elif key == 3: # right arrow key
cv2.setTrackbarPos(trackbar_name,window_name,pos+1)
cap1.set(cv2.CAP_PROP_POS_FRAMES, pos+1)
cap2.set(cv2.CAP_PROP_POS_FRAMES, pos+1)
cap1.release()
cap2.release()
cv2.destroyAllWindows()