Post

[CV] 이미지 슬라이드쇼 만들기

OpenCV를 이용해 이미지 슬라이드쇼 프로그램을 만들어보자.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import glob
import cv2


# image files to a list
img_files = glob.glob('./images/*.jpg')

if not img_files:
    print('No image files.')
    sys.exit()

# make full window screen
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('image', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

# show images
cnt = len(img_files)
idx = 0

while True:
    img = cv2.imread(img_files[idx])

    if img is None:
        print('Image load failed!')
        break

    cv2.imshow('image', img)
    if cv2.waitKey(2000) >= 0: # wait for 2sec
        break

    idx += 1
    if idx >= cnt:
        idx = 0     # go back to the first image

cv2.destroyAllWindows()
This post is licensed under CC BY 4.0 by the author.