MBG0903 commited on
Commit
7b0d413
·
verified ·
1 Parent(s): 996dc27

Update utils/image_io.py

Browse files
Files changed (1) hide show
  1. utils/image_io.py +21 -21
utils/image_io.py CHANGED
@@ -1,38 +1,38 @@
1
  import cv2
2
- import tempfile
 
3
 
4
 
5
- def save_png(img):
 
6
 
7
- temp = tempfile.NamedTemporaryFile(
8
- delete=False,
9
- suffix=".png"
 
 
 
10
  )
11
 
12
  cv2.imwrite(
13
- temp.name,
14
- cv2.cvtColor(
15
- img,
16
- cv2.COLOR_RGB2BGR
17
- )
18
  )
19
 
20
- return temp.name
21
 
22
 
23
- def save_bmp(img):
24
 
25
- temp = tempfile.NamedTemporaryFile(
26
- delete=False,
27
- suffix=".bmp"
28
  )
29
 
30
  cv2.imwrite(
31
- temp.name,
32
- cv2.cvtColor(
33
- img,
34
- cv2.COLOR_RGB2BGR
35
- )
36
  )
37
 
38
- return temp.name
 
1
  import cv2
2
+ import uuid
3
+ import os
4
 
5
 
6
+ OUTPUT_DIR = "outputs"
7
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
8
 
9
+
10
+ def save_bmp(image):
11
+
12
+ filename = os.path.join(
13
+ OUTPUT_DIR,
14
+ f"{uuid.uuid4()}.bmp"
15
  )
16
 
17
  cv2.imwrite(
18
+ filename,
19
+ image,
20
+ [cv2.IMWRITE_BMP_COMPRESSION, 0]
 
 
21
  )
22
 
23
+ return filename
24
 
25
 
26
+ def save_png(image):
27
 
28
+ filename = os.path.join(
29
+ OUTPUT_DIR,
30
+ f"{uuid.uuid4()}.png"
31
  )
32
 
33
  cv2.imwrite(
34
+ filename,
35
+ image
 
 
 
36
  )
37
 
38
+ return filename