forked from adetaylor/simple-image-recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
30 lines (22 loc) · 1.07 KB
/
test.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
__author__ = 'adrian'
import unittest
import os
from scipy import misc
import colourfinder
class ColourFinderTest(unittest.TestCase):
test_image_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testimages")
def recogniseImage(self, filename, colour):
image_data = misc.imread(os.path.join(ColourFinderTest.test_image_path, filename))
return colourfinder.find_blob(image_data, colour)
def assertImageAsExpected(self, filename, colour, expected_x, expected_y, minimum_expected_confidence):
(x, y, confidence) = self.recogniseImage(filename, colour)
self.assertAlmostEqual(expected_x, x)
self.assertAlmostEqual(expected_y, y)
self.assertGreater(minimum_expected_confidence, confidence)
def assertColourNotFound(self, filename, colour):
(x, y, confidence) = self.recogniseImage(filename, colour)
self.assertLess(0.3, confidence)
def test_find_wattle(self):
self.assertImageAsExpected("chicken.jpg", colourfinder.RED, 1850, 1320, 0.5)
if __name__ == "__main__":
unittest.main()