Jupyter Notebook 中 多张图片逐张播放显示
import os
import time
from tqdm import tqdm
from PIL import Image
import cv2
from IPython.display import clear_output, display, HTML
def show_images(images:list,small:int=1) -> str:
"""
images用来存放图片的绝对路径
small用来缩小图像大小,便于显示
"""
current_time = 0
for img_path in tqdm(images):
clear_output(wait=True)
img = cv2.imdecode(np.fromfile(img_path,dtype=np.uint8),-1)
if img is None or not img.any():
continue
h,w,_ = img.shape
if current_time==0:
current_time=time.time()
else:
last_time=current_time
current_time=time.time()
fps = 1. / (current_time - last_time)
text = "FPS: %d" % int(fps)
cv2.putText(img, text , (0,50), cv2.FONT_HERSHEY_TRIPLEX, 1, (255, 0, 0), 1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (int(w / small), int(h / small)))
img = Image.fromarray(img)
display(img)
time.sleep(5)