需要安装python opencv库:sudo apt-get install python-opencv
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
此demo的功能是获取目录下所有文件名,并循环播放其中后缀为.jpg的图片,间隔时间为5秒
'''
import cv2
import time
import os
if __name__ == "__main__":
for root, dirs, files in os.walk("./Image/"):
print "path:",root # 当前目录路径
print "dirs:",dirs # 当前路径下所有子目录
print "files:",files # 当前路径下所有非目录子文件
break
files_copy = files[:] ## 这里列表只有一层,所以用浅拷贝就ok
for pic in files_copy:
if not pic.endswith(".jpg"):
files.remove(pic)
print "remove :",pic
while True:
for pic in files:
img = cv2.imread("./Image/{}".format(pic))
cv2.namedWindow("Image")
cv2.imshow('Image', img)
cv2.waitKey(5000)
cv2.destroyAllWindows()