Ask Your Question

Revision history [back]

Creating high frame rate video using opencv in python

For one of my application i want to write code to process high frame rate videos in which a small white dot in a grayscale image will be moving

in order to start building above application, i wanted to create a high frame rate video in first place for which i have tried to write the following code

import cv2
import numpy as np
# as normal usage thrown me error i am using this
fourcc = cv2.cv.CV_FOURCC(*'XVID')
#last parameter 1, i want to create a grayscale video
writer = cv2.VideoWriter("output.avi", fourcc, 100,(700,500),1)
i = 0
j = 0 
for frame in range(100):
    ref_image_array = np.zeros((700,500),np.uint8)
    #trying to change the circle position in every image
    cv2.circle(ref_image_array,(490-i,690-j),5,255,-1)
    writer.write(ref_image_array)
    i= i + 1
    j= j + 1
writer.release()
print 'Writing Done'
cap = cv2.VideoCapture('output.avi')
while(cap.isOpened()):
    print 'valid file'
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

i find something wrong with the way i am writing , because i am not able to play the video, kindly guide me