TODO in progress
Image Related
TODO
Video Related
Basic video reading
video_file = "path/to/video/file.mp4"
cap = cv2.VideoCapture(video_file)
fps = cap.get(cv2.CAP_PROP_FPS)
length = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("Video File %s ==> fps: %.2f, total: %d frames" % (video_file, fps, length))
video_start = int(0) # start from index 0
video_end = video_start + 50000 # read the first 50000 frames
cap.set(1, video_start)
for frame_index in range(video_start, video_end):
ret, frame = cap.read()
if not ret: break
cv2.putText(frame, "Frame:" + str(frame_index), (20, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
cv2.imshow("frame", frame)
cv2.waitKey(0)
Reading with Specific Index
example: read every 5s
video_file = "path/to/video/file.mp4'"
cap = cv2.VideoCapture(video_file)
fps = cap.get(cv2.CAP_PROP_FPS)
length = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("Video File %s ==> fps: %.2f, total: %d frames" % (video_file, fps, length))
video_start = int(0) # start from index 0
video_end = video_start + 50000 # read the first 50000 frames
cap.set(1, video_start)
for frame_index in range(video_start, video_end):
if not frame_index%int(5*fps)==0: continue
else: cap.set(1, frame_index)
ret, frame = cap.read()
if not ret: break
cv2.putText(frame, "Frame:" + str(frame_index), (20, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
cv2.imshow("frame", frame)
cv2.waitKey(0)
Convert a Video File to Images for Annotation
# install the video-cli package
pip install video-cli
video-toimg your_video.mp4 # this creates your_video/ director