1import numpy as np
2import cv2
3
4cap = cv2.VideoCapture(0)
5
6# Define the codec and create VideoWriter object
7#fourcc = cv2.cv.CV_FOURCC(*'DIVX')
8#out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
9out = cv2.VideoWriter('output.avi', -1, 20.0, (640,480))
10
11while(cap.isOpened()):
12 ret, frame = cap.read()
13 if ret==True:
14 frame = cv2.flip(frame,0)
15
16 # write the flipped frame
17 out.write(frame)
18
19 cv2.imshow('frame',frame)
20 if cv2.waitKey(1) & 0xFF == ord('q'):
21 break
22 else:
23 break
24
25# Release everything if job is finished
26cap.release()
27out.release()
28cv2.destroyAllWindows()
29
1import cv2
2import numpy as np
3import os
4
5image_folder = 'data-set-race-01'
6video_file = 'race-01.mp4'
7image_size = (160, 120)
8fps = 24
9
10images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
11images.sort()
12
13out = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(*'MP4V'), fps, image_size)
14
15img_array = []
16for filename in images:
17 img = cv2.imread(os.path.join(image_folder, filename))
18 img_array.append(img)
19 out.write(img)
20
21out.release()
22