资讯

展开

将视频转换为图片并以时间戳命名(制作orbslam3数据集)

作者:快盘下载 人气:74
import os
import cv2
import datetime
videos_src_path = r;F:/video;
videos_save_path = r;F:/video;
videos = os.listdir(videos_src_path)
i = 0
for each_video in videos:
print(;Video Name :;, each_video)
each_video_name, _ = each_video.split(;.;)
os.mkdir(videos_save_path ; ;/; ; each_video_name)
each_video_save_full_path = os.path.join(videos_save_path, each_video_name) ; ;/;
each_video_full_path = os.path.join(videos_src_path, each_video)
cap = cv2.VideoCapture(each_video_full_path)
frame_count = 1
success = True
while (success):
success, frame = cap.read()
cv2.waitKey(10)
i = i ; 1
if success == True:
# uuid_str = time.strftime(%Y-%m-%d-%H_%M_%S.%f;, time.localtime()) # 图片命名为当前时间
uuid_str = datetime.datetime.now().strftime(%Y-%m-%d %H:%M:%S.%f;)
uuid_str = str(uuid_str)
uuid_str = uuid_str.replace(;:;, ;-;) # 去掉python读取时间中的;;文件命名不能有;
uuid_str = uuid_str.replace(; ;, ;;) # 去掉python读取时间中空格;文件命名不能空格;
uuid_str = uuid_str.replace(;-;, ;;)
uuid_str = uuid_str.replace(;_;, ;;)
if i % 1 == 0:
cv2.imwrite(each_video_save_full_path ; uuid_str ; ;.png;, frame)
# cv2.imwrite(each_video_save_full_path ; uuid_str ; %d.png; % frame_count, frame)
frame_count = frame_count ; 1
print(;Final frame:;, frame_count)

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!