Ask Your Question

Writing/Drawing different things on Video. OpenCV Python

asked 2015-03-23 11:51:04 -0500

shideh gravatar image

My goal is to draw different things on a video then save the video with said drawings. I want the first drawing to show for 5 seconds for example, then second one in another part of the video for another 5 seconds while first drawing is gone.

I'm also trying to save the video (I'm on a Windows machine) but it doesn't read the file after saving. media player gives an error: I used:

fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.MOV',fourcc, 20.0, (640,480))

Here's my code:

import numpy
import cv2

cap = cv2.VideoCapture('video.MOV')

fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.MOV',fourcc, 20.0, (640,480))

    # read the frames
    _,frame =

        #A line
    cv2.line(frame, (500, 400), (640, 480),(0,255,0), 3)

    cv2.putText(frame, "test!",(105, 105),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(225,0,0))
    #if key pressed is 'Esc', exit the loop

    if cv2.waitKey(33)== 27:

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-03-25 12:15:21 -0500

shideh gravatar image
if ((time.time() - start_time) < 5.1):
    cv2.putText(frame, "test!",(50, 50),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,255))
#Shows the change after the certain amount of time    
elif ((time.time() - start_time) < 10.1):
    cv2.putText(frame, "test2!",(50, 50),cv2.FONT_HERSHEY_COMPLEX_SMALL,.7,(0,0,255))
#After all displays are done, resets the start time back to current time
if ((time.time() - start_time) >= 10.1):
    start_time = time.time()
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-03-23 11:51:04 -0500

Seen: 13,778 times

Last updated: Mar 25 '15