▶ Slide Show 구현은 폴더 내 다수의 Image 저장 후 while문 돌면서 1개씩 Image Show 해주는 방식
import sys
import glob
import cv2
# 이미지 파일을 모두 img_files 리스트에 추가
# 특정 패턴의 문자열에 있는 파일들을 모두 불러옴 (.jpg)
img_files = glob.glob('.\\images\\*.jpg')
# os.listdir 이용 시,,,
file_list = os.listdir('.\\images')
# jpg로 되어 있는 파일 모두를 불러옴
img_files = [file for file in file_list if file.endwith('.jpg')]
#
if not img_files:
print("There are no jpg files in 'images' folder")
sys.exit()
# WINDOW_NORMAL, 전체 화면으로 'image' 창 생성
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('image', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cnt = len(img_files)
idx = 0
# 무한 루프
while True:
img = cv2.imread(img_files[idx])
if img is None:
print("IMAGE LOAD FAIL" )
break
cv2.imshow("image",img)
# 1초마다 갱신
if cv2.waitKey(1000) >= 0:
break
# total image slide show 종료 시, 다시 처음으로...
idx += 1
if idx >= cnt: # cnt는 폴더 내, 이미지 총 개수
idx = 0
cv2.destroyAllWindows()
'Language - Python(Opencv)' 카테고리의 다른 글
Python Opencv - #4 영상의 생성, 복사, 부분 영상 추출 (0) | 2021.11.21 |
---|---|
Python Opencv - #3 영상의 속성과 픽셀 값 참조 (0) | 2021.11.21 |
Python Opencv - #1 Image Load, Show (0) | 2021.11.21 |
Python - Opencv 기본 설정 (0) | 2021.11.21 |
Python - 기하학적인 이미지 변환 (0) | 2021.11.19 |