From b7edb589b1ec7bc9fc95b94cc1b5232237a55de6 Mon Sep 17 00:00:00 2001 From: Seth T Date: Tue, 23 May 2017 11:53:29 -0400 Subject: [PATCH 1/3] Typo --- .../10-Color-Tracking/black_grayscale_line_following.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py index c5a31cfed..30cc9ad07 100644 --- a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py +++ b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py @@ -20,7 +20,7 @@ GRAYSCALE_THRESHOLD = [(0, 64)] # will then be averaged with different weights where the most weight is assigned # to the roi near the bottom of the image and less to the next roi and so on. ROIS = [ # [ROI, weight] - (0, 100, 160, 20, 0.7), # You'll need to tweak the weights for you app + (0, 100, 160, 20, 0.7), # You'll need to tweak the weights for your app (0, 050, 160, 20, 0.3), # depending on how your robot is setup. (0, 000, 160, 20, 0.1) ] From 7b62d97cbb01a8f9267c85a381f7981b58e2fbf7 Mon Sep 17 00:00:00 2001 From: Seth T Date: Tue, 23 May 2017 11:54:07 -0400 Subject: [PATCH 2/3] Clarify numeric literals are not in octal --- .../10-Color-Tracking/black_grayscale_line_following.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py index 30cc9ad07..ad2f2ab7b 100644 --- a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py +++ b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py @@ -21,8 +21,8 @@ GRAYSCALE_THRESHOLD = [(0, 64)] # to the roi near the bottom of the image and less to the next roi and so on. ROIS = [ # [ROI, weight] (0, 100, 160, 20, 0.7), # You'll need to tweak the weights for your app - (0, 050, 160, 20, 0.3), # depending on how your robot is setup. - (0, 000, 160, 20, 0.1) + (0, 50, 160, 20, 0.3), # depending on how your robot is setup. + (0, 0, 160, 20, 0.1) ] # Compute the weight divisor (we're computing this so you don't have to make weights add to 1). From e040b8e87cef02f3d8d0b2732d7f1d0485f4ed36 Mon Sep 17 00:00:00 2001 From: Seth T Date: Tue, 23 May 2017 11:56:53 -0400 Subject: [PATCH 3/3] Simplify finding largest_blob --- .../black_grayscale_line_following.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py index ad2f2ab7b..43523a256 100644 --- a/usr/examples/10-Color-Tracking/black_grayscale_line_following.py +++ b/usr/examples/10-Color-Tracking/black_grayscale_line_following.py @@ -46,20 +46,15 @@ while(True): for r in ROIS: blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=r[0:4], merge=True) # r[0:4] is roi tuple. if blobs: - # Find the index of the blob with the most pixels. - most_pixels = 0 - largest_blob = 0 - for i in range(len(blobs)): - if blobs[i].pixels() > most_pixels: - most_pixels = blobs[i].pixels() - largest_blob = i + # Find the blob with the most pixels. + largest_blob = max(blobs, key=lambda b: b.pixels()) # Draw a rect around the blob. - img.draw_rectangle(blobs[largest_blob].rect()) - img.draw_cross(blobs[largest_blob].cx(), - blobs[largest_blob].cy()) + img.draw_rectangle(largest_blob.rect()) + img.draw_cross(largest_blob.cx(), + largest_blob.cy()) - centroid_sum += blobs[largest_blob].cx() * r[4] # r[4] is the roi weight. + centroid_sum += largest_blob.cx() * r[4] # r[4] is the roi weight. center_pos = (centroid_sum / weight_sum) # Determine center of line.