Jupyter Notebook中多张图片逐张播放显示

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
        ########这里可以对图像进行处理操作###########
        # 画出一个框
       #    cv2.rectangle(img, (500, 300), (800, 400), (0, 0, 255), 5, 1, 0)
        # 上下翻转
        # img= cv2.flip(img, 0)
        
        
        #######################################
        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)
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值