-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intake.py
59 lines (43 loc) · 1.69 KB
/
Intake.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
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
from Blob import BlobDetector
import Utility
import numpy as np
class Intake:
def __init__(self):
# Vision data
self.ball_detected = False
# Vision constants
self.max_balls = 5
self.min_balls = 1
self.blue_hsv_lower = np.array([99, 71, 78])
self.blue_hsv_upper = np.array([123, 255, 255])
self.red_hsv_lower = np.array([0, 87, 0])
self.red_hsv_upper = np.array([10, 255, 255])
self.red_hsv_lower2 = np.array([170, 87, 0])
self.red_hsv_upper2 = np.array([180, 255, 255])
# Blob detectors
self.blue_blob_detector = BlobDetector(self.blue_hsv_lower, self.blue_hsv_upper)
self.red_blob_detector = BlobDetector(self.red_hsv_lower, self.red_hsv_upper, self.red_hsv_lower2,
self.red_hsv_upper2)
self.output_frame = None
# Returned frame must be same size as input frame. Draw on the given frame.
def process(self, frame):
# Find blue blobs
num_blue = self.blue_blob_detector.process(frame)
# Find red blobs
num_red = self.red_blob_detector.process(frame)
self.output_frame = np.copy(frame)
if self.min_balls <= num_red + num_blue <= self.max_balls:
self.ball_detected = True
else:
self.ball_detected = False
# utility.put_text_group(frame, ('Balls? ' + str(self.ball_detected), ))
def get_output_values(self):
return (self.ball_detected, ) # return tuple
def get_output_frames(self):
return [
{
'name': 'final',
'frame': self.output_frame
},
]