Skip to content

Commit 578f911

Browse files
Calculate accuracy and distance that each prediction is wrong by (where 0 is it being correct)
Print out accuracy and the average wrong by distance. Fix profile for set-1. The threshold needed to be a bit tighter due to the wooden table containing similar color values
1 parent 91f8d99 commit 578f911

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

algorithm.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
def runAlgorithm(dir):
8+
numCorrect = 0
9+
numWrong = 0
10+
wrongByDistance = list()
11+
812
# Loop through each file in directory
913
for name in os.listdir(dir):
1014
fullPath = os.path.join(dir, name)
@@ -39,9 +43,18 @@ def runAlgorithm(dir):
3943
print('Found filename that does not start with a valid number: %s' % (name2))
4044
continue
4145

42-
print('yay %s' % fullPath2)
4346
image = scipy.misc.imread(fullPath2)
4447
predictedFingerCount = detectFingerCount(image, colorProfile)
4548

46-
# TODO Check if we got it right. Also, store statistics and analyze how we did
47-
print('Should be: %i Got: %i' % (actualFingerCount, predictedFingerCount))
49+
print('Should be: %i Got: %i' % (actualFingerCount, predictedFingerCount))
50+
if predictedFingerCount == actualFingerCount:
51+
numCorrect = numCorrect + 1
52+
else:
53+
numWrong = numWrong + 1
54+
55+
wrongByDistance.append(np.abs(predictedFingerCount - actualFingerCount))
56+
57+
accuracy = numCorrect / (numCorrect + numWrong)
58+
averageWrongBy = sum(wrongByDistance) / len(wrongByDistance)
59+
print('Algorithm Accuracy: %f%%' % (accuracy * 100))
60+
print('Average Algorithm Wrong By: %f' % (averageWrongBy))

data/training/set-1/profile.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<profile SchemaVersion="1">
2-
<ycbcr minY="0" maxY="255" minCb="77" maxCb="127" minCr="145" maxCr="180" />
2+
<ycbcr minY="120" maxY="255" minCb="77" maxCb="127" minCr="140" maxCr="180" />
33
</profile>

detectFingerCount.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def detectFingerCount(image, colorProfile):
4444
# Apply threshold based on color profile
4545
imageMask = thresholdYCbcr(imageYCbCr, colorProfile[0, :], colorProfile[1, :])
4646

47+
# # Testing image mask
48+
# imageMask = thresholdYCbcr(imageYCbCr, np.array([120, 77, 140]), np.array([255, 127, 180]))
49+
4750
# # Show YCbCr image and final mask
4851
# plt.figure(1)
4952
# plt.clf()
@@ -172,4 +175,4 @@ def detectFingerCount(image, colorProfile):
172175
# plt.waitforbuttonpress()
173176

174177
# Number of fingers up is webs plus one
175-
return fingerWebs + 1
178+
return min(fingerWebs + 1, 5)

0 commit comments

Comments
 (0)