-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreprocessing.py
55 lines (45 loc) · 1.58 KB
/
preprocessing.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import cv2
import os
from image_processing import func
if not os.path.exists("temp"):
os.makedirs("temp")
if not os.path.exists("temp/train"):
os.makedirs("temp/train")
if not os.path.exists("temp/test"):
os.makedirs("temp/test")
path="data3/train" #coloured images here
path1 = "temp" #black and white images stored here
label=0 #number of characters
var = 0 #total number of images
c1 = 0 #total images in train
c2 = 0 #number images in test
for (dirpath,dirnames,filenames) in os.walk(path):
for dirname in dirnames:
print(dirname)
for(direcpath,direcnames,files) in os.walk(path+"/"+dirname):
if not os.path.exists(path1+"/train/"+dirname):
os.makedirs(path1+"/train/"+dirname)
if not os.path.exists(path1+"/test/"+dirname):
os.makedirs(path1+"/test/"+dirname)
num=0.8*len(files)
#num = 100000000000000000
i=0
for file in files:
var+=1
actual_path=path+"/"+dirname+"/"+file
actual_path1=path1+"/"+"train/"+dirname+"/"+file
actual_path2=path1+"/"+"test/"+dirname+"/"+file
img = cv2.imread(actual_path, 0)
bw_image = func(actual_path)
if i<num:
c1 += 1
cv2.imwrite(actual_path1 , bw_image)
else:
c2 += 1
cv2.imwrite(actual_path2 , bw_image)
i=i+1
label=label+1
print(var)
print(c1)
print(c2)
print(label)