-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
36 lines (35 loc) · 1.19 KB
/
Main.py
File metadata and controls
36 lines (35 loc) · 1.19 KB
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
import os,cv2,csv
from tqdm import tqdm
from ColorClassify import ColorClassify
from Thresholding import Thresholding
from MakeContour import MakeContour
class Main():
def __init__(self):
pass
def process(self,inputPath,processFolder,outputFile):
fp = open(outputFile,"w")
writer = csv.writer(fp)
writer.writerow(['ImageId','EncodedPixels'])
directories = os.listdir(inputPath)
for dr in tqdm(directories):
path = os.path.join(inputPath,dr)
path = os.path.join(path,'images')
files = os.listdir(path)
for f in files:
fPath = os.path.join(path,f)
img = cv2.imread(fPath)
imgType = ColorClassify().classify(img)
imgNew = Thresholding().thresholdImage(fPath,imgType)
cv2.imwrite(os.path.join(processFolder,f+imgType+".png"),img)
if imgType=="black":
imgNew = 255-imgNew
if Thresholding().errorFix(imgNew):
imgNew = 255-imgNew
tmpPath = os.path.join("/tmp",f)
cv2.imwrite(tmpPath,imgNew)
imgNew,runEncodeOutput = MakeContour().contours(tmpPath)
os.system("sudo rm \""+tmpPath+"\"")
cv2.imwrite(os.path.join(processFolder,f),imgNew)
for row in runEncodeOutput:
writer.writerow(row)
fp.close()