1.导入相关模块
import time
import cv2 as cv
import os
import sys
from itertools import cycle
2.单窗口显示图片
# OpenCV窗口显示
img = cv.imread('C:/Users/Administrator/Desktop/New_Study/IMAGE/Pictures/1.jpg')
cv.namedWindow('Show image ',cv.WINDOW_NORMAL)
cv.imshow('Show image ', img)
cv.waitKey()
cv.destroyAllWindows()
# OpenCV窗口循环显示
frame_path = "C:/Users/Administrator/Desktop/New_Study/IMAGE/Pictures"
filenames = os.listdir(frame_path)
# 通过itertools.cycle生成一无限循环的迭代器,每次迭代都输出下一章图像对象
img_iter = cycle([cv.imread(os.sep.join([frame_path, x])) for x in filenames])
key = 0
# 按ESC键结束循环播放,ESC的ASCII码为27,即0001 1011
while key & 0xFF != 27:
#cv.namedWindow可以使窗口统一,但是图像会失真,不加则窗口大小不同
cv.namedWindow('Kawaii Small Animals',cv.WINDOW_NORMAL)
cv.imshow('Kawaii Small Animals', next(img_iter))
key = cv.waitKey(500)
# cv.waitKey()参数不为0的时候则可以和循环结合产生动态画面
cv.destroyAllWindows()
特别注明:本文属于Python OpenCV学习笔记,不以盈利为目的,纯手工码字不容易,若整理的笔记中,对您有所助益,麻烦点个赞或者收藏,万分感谢!如有构成侵权的地方,请联系作者删除,谢谢合作!