def get_frames_every_x_sec(video, secs=1, fmt='opencv'):
vidcap = cv2.VideoCapture(video)
fps = get_frame_rate(vidcap)
inc = int(fps * secs)
length = int(vidcap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
count = 0
while vidcap.isOpened() and count <= length:
if count % inc == 0:
success, image = vidcap.read()
if success:
cv2_im = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
if fmt == 'PIL':
im = Image.fromarray(cv2_im)
#elif fmt == 'DISK':
#cv2.imwrite(os.path.join(path_output_dir, '%d.png') % count, image)
else:
im = cv2_im
yield count, im
else:
break
count += 1
cv2.destroyAllWindows()
vidcap.release()
# image region: img = img[c1:c1+25,r1:r1+25] # roi = gray[y1:y2, x1:x2]
评论列表
文章目录