From 98a086effea666fb4123b7eee37bb076fd9977be Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 19 Jun 2014 23:21:59 +0200 Subject: [PATCH] Update Python examples --- usr/examples/circle.py | 3 ++- usr/examples/fb_viewer.py | 9 ++++++++- usr/examples/template_matching.py | 23 +++++++++++++++-------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/usr/examples/circle.py b/usr/examples/circle.py index 24c8e0f07..33862a7eb 100644 --- a/usr/examples/circle.py +++ b/usr/examples/circle.py @@ -5,4 +5,5 @@ sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_brightness(-2) image = sensor.snapshot() -image.draw_circle((50, 50), 10) \ No newline at end of file +image.draw_circle((50, 50), 10) +image.draw_rectangle((10, 10, 50, 50)) \ No newline at end of file diff --git a/usr/examples/fb_viewer.py b/usr/examples/fb_viewer.py index e843f520f..6a474bda6 100644 --- a/usr/examples/fb_viewer.py +++ b/usr/examples/fb_viewer.py @@ -1,4 +1,11 @@ -import sensor +import sensor, time, led + +# Set sensor contrast +sensor.set_contrast(1) +# Set sensor brightness +sensor.set_brightness(-1) +# Set sensor pixel format sensor.set_pixformat(sensor.RGB565) + while (True): image = sensor.snapshot() diff --git a/usr/examples/template_matching.py b/usr/examples/template_matching.py index 9d34c5f57..bbcc9fa0d 100644 --- a/usr/examples/template_matching.py +++ b/usr/examples/template_matching.py @@ -1,11 +1,18 @@ -import sensor, imlib, time +import sensor, time +# Set sensor contrast +sensor.set_contrast(1) +# Set sensor brightness +sensor.set_brightness(-2) +# Set sensor to pixel format sensor.set_pixformat(sensor.GRAYSCALE) -template = imlib.load_template("0:/minion.template") -clock = time.clock() + +# Load template +template = Image("0:/template.pgm") + +# Run template matching while (True): - clock.tick() image = sensor.snapshot() - obj = imlib.template_match(image, template, 0.7) - if obj: - imlib.draw_rectangle(image, obj) - print (clock.fps()) + r = image.find_template(template, 0.75) + if r: + image.draw_rectangle(r) + time.sleep(50)