-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdataset_converter.py
More file actions
33 lines (23 loc) · 788 Bytes
/
Copy pathdataset_converter.py
File metadata and controls
33 lines (23 loc) · 788 Bytes
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
import cv2
import numpy as np
import sys, os
from tqdm import *
from os import listdir
from os.path import isfile, join
'''
Recursively load images in the directory and concate images together into a numpy array
mypath: input directory
out: output directory
'''
import logging
logging.basicConfig(format='[%(asctime)s] %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
mypath = sys.argv[1]
out = sys.argv[2]
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
logging.info('Convert images at %s to %s' % (mypath, out))
datas = []
for i in tqdm(range(len(onlyfiles))):
img = cv2.cvtColor(cv2.imread(mypath + '/' + onlyfiles[i]), cv2.COLOR_RGB2GRAY)
datas.append(img.flatten())
datas = np.asarray(datas)
np.save(out, datas)