yolo_standard_libray/033读取mp4帧保存成图片.py
2025-06-24 10:56:15 +08:00

37 lines
894 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# url =
import cv2
# 打开视频文件
# video_path = "/home/admin-root/haotian/锻8/tensorrtx/yolov8/video/180.50.13.253_07_2025042215303747.mp4"
video_path = "/home/admin-root/haotian/锻8/tensorrtx/yolov8/video/测试视频20250621.mp4"
cap = cv2.VideoCapture(video_path)
# 检查是否成功打开视频
if not cap.isOpened():
print("Error: Could not open video.")
exit()
n = 0
# 逐帧读取视频
while True:
# 读取一帧ret为是否读取成功frame为帧数据
ret, frame = cap.read()
# 如果读取失败(如视频结束),退出循环
if not ret:
print("Reached end of video.")
break
# 在此处处理帧数据(例如显示、保存、分析等)
cv2.imwrite(f"./images_20250623/mp4_{n}.jpg", frame)
print(f"保存图片{n}")
n += 1
# 释放资源
cap.release()
# cv2.destroyAllWindows()