可以同时读取图片或者视频:
from natsort import natsorted
import cv2
import glob
import numpy as np
if __name__ == '__main__':
path ="aaaa.mp4"
if "mp4" in path:
vid_path =path
cap =cv2.VideoCapture(path)
else:
vid_path =r'/data/imgs/'
files =glob.glob(vid_path +"*.jpg")
files =natsorted(files)
track_total=0
while True:
track_total+=1
if "weilan2" in vid_path:
ret, img_raw = cap.read()
img_raw = img_raw[300:-300, :]
elif "yuexian" in vid_path:
ret, img_raw = cap.read() # img_raw=img_raw[:800,:]
else:
image_name = files[track_total]
img_raw = cv2.imread(image_name)
if img_raw is None:
break
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/jacke121/article/details/121413157
内容来源于网络,如有侵权,请联系作者删除!