Error Using contour value to play certain frame of video OpenCV-Python -
hi , thank stopping by,
you see, i'm trying use opencv's tracking blob x , y position of moving object in camera synced match equivalent frame in video.
so means if hand on left of screen positions video frame 1, , if on right it's frame 300, let's say. every time frame 250 reached, 1 added counter. after counter gets 20, changes video , uses y axis synced.
my problem when try make work, either part of video synced motion (from frame 1 30 let's say), or frames return , mmco error. here code:
contours of themoving objects:
#loop on contours c in cnts: global motion_frame_x global motion_frame_y global motioncounter if len(cnts) != 0: c = max(cnts, key = cv2.contourarea) x_value = tuple(c[c[:, :, 0].argmax()][0]) y_value = tuple(c[c[:, :, 1].argmax()][0]) print 'x: ' , x_value[0], 'y: ', y_value[1] print "counter: " , motioncounter motion_frame_x = x_value[0] / 500.0 motion_frame_y = y_value[1] / 500.0
that's counter:
#motion counter if motion_frame_x >= 0.5 , motioncounter < 20: motioncounter = motioncounter + 1 print motion_frame_x elif motioncounter >= 20 , motion_frame_y >= 0.85: motioncounter = motioncounter + 1 print motion_frame_y elif motioncounter == 50: break
and video output:
#video output if motioncounter < 20: cap = cv2.videocapture('vid1.mp4') cap.set(1, round(motion_frame_x * 292, 1) / 24) elif motioncounter >= 20 , motioncounter < 50: cap= cv2.videocapture('vid2.mp4') else: cap= cv2.videocapture('vid3.mp4') ret, vid = cap.read() color = cv2.cvtcolor(vid, cv2.color_bgr2rgb) cv2.imshow('vid', color) if cv2.waitkey(1) & 0xff == ord('q'): break rawcapture.truncate(0)
if lower division on cap.set can see bit more of video still not entirely. , if put motion_frame_x in video doesnt move , gives me buffer error.
thank help!
Comments
Post a Comment