ginipick commited on
Commit
7f3748b
ยท
verified ยท
1 Parent(s): ce62711

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -5,19 +5,22 @@ import cv2
5
  import os
6
 
7
  def image_to_video(image):
8
- image_array = np.array(image.convert('RGB')) # ์ด๋ฏธ์ง€๋ฅผ RGB๋กœ ๋ณ€ํ™˜
 
 
 
 
9
 
10
- # ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •
11
- output_path = 'output_video.mp4' # ๊ฒฝ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ„์†Œํ™”๋œ ๊ฒฝ๋กœ ์‚ฌ์šฉ
12
- if not os.path.exists('output'): # 'output' ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด ์ƒ์„ฑ
13
  os.makedirs('output')
14
- output_path = os.path.join('output', output_path) # ํŒŒ์ผ ๊ฒฝ๋กœ ์™„์„ฑ
15
 
16
- height, width, _ = image_array.shape
17
  size = (width, height)
18
- fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 'mp4v' ์ฝ”๋ฑ ์‚ฌ์šฉ
19
 
20
- video = cv2.VideoWriter(output_path, fourcc, 30, size) # ํ”„๋ ˆ์ž„ ์†๋„๋ฅผ 30์œผ๋กœ ์„ค์ •
21
 
22
  if not video.isOpened():
23
  print("๋น„๋””์˜ค ์ž‘์„ฑ์ž๊ฐ€ ํŒŒ์ผ์„ ์—ด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")
 
5
  import os
6
 
7
  def image_to_video(image):
8
+ # PIL ์ด๋ฏธ์ง€๋ฅผ NumPy ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , RGB ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜
9
+ image_array = np.array(image.convert('RGB'))
10
+
11
+ # OpenCV๋Š” BGR ํ˜•์‹์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ RGB์—์„œ BGR๋กœ ์ƒ‰์ƒ ์ฑ„๋„์„ ์žฌ์ •๋ ฌ
12
+ image_array = cv2.cvtColor(image_array, cv2.COLOR_RGB2BGR)
13
 
14
+ output_path = 'output_video.mp4'
15
+ if not os.path.exists('output'):
 
16
  os.makedirs('output')
17
+ output_path = os.path.join('output', output_path)
18
 
19
+ height, width, layers = image_array.shape
20
  size = (width, height)
21
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
22
 
23
+ video = cv2.VideoWriter(output_path, fourcc, 30, size)
24
 
25
  if not video.isOpened():
26
  print("๋น„๋””์˜ค ์ž‘์„ฑ์ž๊ฐ€ ํŒŒ์ผ์„ ์—ด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")