Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2012-10-23 10:24:21 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2012-10-23 10:24:21 (GMT)
commit633f1fb61b910e51073f34913202a249ec0d5c3c (patch)
tree94ab9bdfe09c3c99076e3a4191c0aa6674ccec30
parentef8d0d0f2a63c3cb1edae57e95f2cb6a4d5b0b65 (diff)
check for the count of pixels
-rwxr-xr-xfollowme.py12
-rwxr-xr-xmain.py4
-rwxr-xr-xrobot.py2
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()
diff --git a/main.py b/main.py
index bfe2de3..9efa5c4 100755
--- a/main.py
+++ b/main.py
@@ -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:
diff --git a/robot.py b/robot.py
index adf8536..8860e56 100755
--- a/robot.py
+++ b/robot.py
@@ -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')