diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2012-10-23 10:24:21 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2012-10-23 10:24:21 (GMT) |
commit | 633f1fb61b910e51073f34913202a249ec0d5c3c (patch) | |
tree | 94ab9bdfe09c3c99076e3a4191c0aa6674ccec30 | |
parent | ef8d0d0f2a63c3cb1edae57e95f2cb6a4d5b0b65 (diff) |
check for the count of pixels
-rwxr-xr-x | followme.py | 12 | ||||
-rwxr-xr-x | main.py | 4 | ||||
-rwxr-xr-x | robot.py | 2 |
3 files changed, 12 insertions, 6 deletions
diff --git a/followme.py b/followme.py index c1833d1..f791412 100755 --- a/followme.py +++ b/followme.py @@ -134,7 +134,12 @@ class FollowMe(object): conexa = mascara.connected_component() - return conexa + if (conexa.count() > pixels): + x, y = conexa.centroid() + else: + x, y = (-1, -1) + + return conexa, (x, y) def generate_capture_to_show(self): if self.use_threshold_view: @@ -142,9 +147,8 @@ class FollowMe(object): else: self.captura_to_show = pygame.transform.scale(self.captura, (int(self.show_size[0]), int(self.show_size[1]))) - def show_centroid_position(self, mask): - x, y = mask.centroid() - pygame.draw.rect(self.captura_to_show, (255,0,0), (x*self.c1, y*self.c2, 20, 20), 16) + def show_centroid_position(self, pos): + pygame.draw.rect(self.captura_to_show, (255,0,0), (pos[0]*self.c1, pos[1]*self.c2, 20, 20), 16) def show_outline(self, mask): points = mask.outline() @@ -117,10 +117,10 @@ class Main: if self.parent: self.parent.put_color(self.colorC) else: - mask = self.c.get_position(self.colorC, self.threshold, self.pixels) + mask, pos = self.c.get_position(self.colorC, self.threshold, self.pixels) self.c.generate_capture_to_show() if self.show: - self.c.show_centroid_position(mask) + self.c.show_centroid_position(pos) if self.c.use_outline_view: self.c.show_outline(mask) if self.c.use_rects_view: @@ -133,4 +133,6 @@ class Robot(object): self.butia.set2MotorSpeed(str(vel_actual[0]), str(vel_actual[1]), str(vel_actual[2]), str(vel_actual[3])) + def stop_robot(self): + self.butia.set2MotorSpeed('0', '0', '0', '0') |