video-io
## read
video_cap = cv2.VideoCapture(video_file)
video_fps = int(video_cap.get(cv2.CAP_PROP_FPS))
video_imh = int(video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
video_imw = int(video_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
video_nfr = int(video_cap.get(cv2.CAP_PROP_FRAME_COUNT))
is_cap, frame = video_cap.read()
while is_cap:
# do something amazing
is_cap, frame = video_cap.read()
video_cap.release()
## write
’‘’
*'XVID' --> MPEG-4编码类型,文件名后缀为.avi
*'MP4V' --> MPEG-4编码 文件名后缀为.mp4
‘’‘
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video_writer = cv2.VideoWriter(out_file, fourcc, video_fps, (video_imw, video_imh))
plot
# 1 : cv2.IMREAD_COLOR,2 : cv2.IMREAD_GRAYSCALE,3 : cv2.IMREAD_UNCHANGED # RGBD
cv2.imread(img_file, flags=1)
# tl : top-left, br : bottom-right, bl : bottom-left
cv2.rectange(img, tl, br, color=(0, 255, 0), thickness=2)
cv2.putText(img, textstr, bl, \
fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1.0,
color=(255, 0, 255), thickness=1) # thickness should be int
cv2.circle(img, center, radius=2, color=(255, 0, 0), thickness=2)