-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageProcessingUnitCases.py
49 lines (37 loc) · 1.92 KB
/
ImageProcessingUnitCases.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
import Filtration
import cv2
import os
class UnitCases:
def listCases(self,unitCaseImageDirectory):
for imageName in os.listdir(unitCaseImageDirectory):
if imageName[-4:] == ".png":
imageFullFileName = os.path.join(unitCaseImageDirectory, imageName)
foundTargetFullFileName = os.path.join(unitCaseImageDirectory, imageName[:-4] + ".txt")
with open(foundTargetFullFileName) as f:
foundTargetString = f.read()
foundTarget = foundTargetString == "T" or foundTargetString == "t" or foundTargetString == " T" or foundTargetString == " t"
with open(imageFullFileName) as f:
image = cv2.imread(imageFullFileName)
yield foundTarget,image
def __init__(self, unitCaseImageDirectory):
totalImages = 0
correctImages = 0
wrongImages = 0
for unitCaseBooleanFoundTarget, unitCaseImage in self.listCases(unitCaseImageDirectory):
foundTarget, correctTargetList = Filtration.findTarget(unitCaseImage)
totalImages += 1
if foundTarget == unitCaseBooleanFoundTarget:
correctImages+=1
else:
wrongImages+=1
cv2.imwrite("/Users/seandoyle/git/AndromedaVision/FailedImageProcessingImages12-28/image%d.png" % wrongImages, unitCaseImage)
f = open('/Users/seandoyle/git/AndromedaVision/FailedImageProcessingImages12-28/image%d.txt' % wrongImages, "w")
if unitCaseBooleanFoundTarget:
f.write("T")
else:
f.write("F")
f.close
print "The number correct is: " , correctImages
print "The total images is: ", totalImages
path = '/Users/seandoyle/git/AndromedaVision/ImageUnitCases12-28'
unitCases = UnitCases(path)