-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_size.py
33 lines (31 loc) · 898 Bytes
/
image_size.py
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
from PIL import Image
import cv2
import sys
import os
import csv
def size(dir, output_file = None):
list = []
for f in os.listdir(dir):
try:
image = cv2.imread(dir+"/"+f)
width, height, depth = image.shape
list.append([f, width, height, depth, image.dtype])
except Exception as e:
list.append([f, "", "", "", ""])
continue
if output_file is None:
return list
else:
with open(output_file, 'w') as outputCsv:
writer = csv.writer(outputCsv)
for l in list:
writer.writerow(l)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("[ERROR] Geef file mee voor ids")
exit()
if len(sys.argv) < 3:
for (f, w, h, d, type) in size(sys.argv[1]):
print(f,w,h,d,type)
else:
size(sys.argv[1], sys.argv[2])