-
Notifications
You must be signed in to change notification settings - Fork 0
/
denominations.py
48 lines (40 loc) · 2.28 KB
/
denominations.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
from common_image_utils import *
denomination_red_color_bounds = ColorBounds(lower_bounds = [65, 50, 150], upper_bounds = [80, 80, 160])
denomination_green_color_bounds = ColorBounds(lower_bounds = [65, 100, 70], upper_bounds = [80, 120, 80])
denomination_yellow_color_bounds = ColorBounds(lower_bounds = [100, 220, 230], upper_bounds = [130, 250, 255])
denomination_grey_color_bounds = ColorBounds(lower_bounds = [100, 100, 100], upper_bounds = [130, 130, 130])
class TenEurosPredicate(ImagePredicate):
def test(self, image):
colorRangeExtractor = ColorRangeImageExtractor(denomination_red_color_bounds)
red_image = colorRangeExtractor.extract(image)
ratio_to_black = get_ratio_to_black(red_image) * 10000
return ratio_to_black >= 75 and ratio_to_black <= 90
class HundredEurosPredicate(ImagePredicate):
def test(self, image):
colorRangeExtractor = ColorRangeImageExtractor(denomination_green_color_bounds)
green_image = colorRangeExtractor.extract(image)
ratio_to_black = get_ratio_to_black(green_image) * 10000
return ratio_to_black >= 75 and ratio_to_black <= 90
class TwoHundredEurosPredicate(ImagePredicate):
def test(self, image):
colorRangeExtractor = ColorRangeImageExtractor(denomination_yellow_color_bounds)
yellow_image = colorRangeExtractor.extract(image)
ratio_to_black = get_ratio_to_black(yellow_image) * 10000
return ratio_to_black >= 450 and ratio_to_black <= 500
class FiveEurosPredicate(ImagePredicate):
def test(self, image):
colorRangeExtractor = ColorRangeImageExtractor(denomination_grey_color_bounds)
grey_image = colorRangeExtractor.extract(image)
ratio_to_black = get_ratio_to_black(grey_image) * 10000
return ratio_to_black >= 1100 and ratio_to_black <= 1150
class DenominationImageValueProvider(ImageValueProvider):
predicate_values = [(TenEurosPredicate(), 10.0),
(HundredEurosPredicate(), 100.0),
(TwoHundredEurosPredicate(), 200.0),
(FiveEurosPredicate(), 5.0)]
def __init__(self, image):
super().__init__(image)
def provide(self):
for predicate, value in self.predicate_values:
if predicate.test(self.image):
return value