import cv2
import os
def creat_file(path):
for i in range(15):
dst = path+'\\'+str(i)
if not os.path.exists(dst):
os.makedirs(dst)
pass
creat_file(r'F:\EB\Projects\video_compare\ori_data\img')
path2 = os.listdir(r'F:\EB\Projects\video_compare\ori_data')
i = 0
for path_num in path2:
if path_num.endswith('.3gp'):
path_f = r'F:\EB\Projects\video_compare\ori_data'+'\\'+path_num
vc = cv2.VideoCapture(path_f)#读取视频 或者获取摄像头
# 检查是否打开正确
j = 0
if vc.isOpened():
open, frame = vc.read()#每一帧 open=ture 有帧
else:
open = False
while True:
ret, frame = vc.read()
if frame is None: #帧
break
if ret == True:
RGB = cv2.cvtColor(frame,1)#, cv2.COLOR_BGR2GRAY
cv2.imshow('result',RGB)
cv2.imwrite(r'F:\EB\Projects\video_compare\ori_data\img'+'\\'+str(i)+'\\'+str(j)+'.jpg',RGB)
j += 1
if cv2.waitKey(1) & 0xFF == 27: #27 esc 10就是等多久 0就是任意键终止
break
i += 1
vc.release()
cv2.destroyAllWindows()
视频检索-视频帧提取
最新推荐文章于 2024-04-02 15:54:39 发布