Update Python examples

This commit is contained in:
iabdalkader 2014-04-04 21:08:33 +02:00
parent 91099e9edc
commit 08a2e41167
8 changed files with 41 additions and 18 deletions

View File

@ -0,0 +1,5 @@
import sensor, time
sensor.set_pixformat(sensor.GRAYSCALE)
fb = sensor.snapshot()
img = Image("minion.pgm")
fb.blit((0, 0), img)

View File

@ -9,7 +9,7 @@ while (True):
# detect blobs
image.threshold((255, 127, 127), 40)
image.median(3)
blobs = image.count_blobs()
blobs = image.find_blobs()
# draw rectangles around detected blobs
image = sensor.snapshot()

8
usr/examples/circle.py Normal file
View File

@ -0,0 +1,8 @@
import sensor
# Set sensor to grayscale
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_brightness(-2)
image = sensor.snapshot()
image.draw_circle((50, 50), 10)

View File

@ -1,19 +1,19 @@
import sensor, imlib, time
import sensor, time
# Set sensor gainceiling
sensor.set_gainceiling(sensor.X8)
sensor.set_gainceiling(16)
# Set sensor brightness
sensor.set_brightness(-2)
# Set sensor to grayscale
sensor.set_pixformat(sensor.GRAYSCALE)
# Load Haar Cascade
cascade = imlib.load_cascade("0:/frontalface_default.cascade")
cascade = HaarCascade("0:/frontalface_default.cascade")
print(cascade)
clock = time.clock()
while (True):
clock.tick()
image = sensor.snapshot()
objects = imlib.detect_objects(image, cascade)
objects = image.find_features(cascade)
for r in objects:
imlib.draw_rectangle(image, r)
image.draw_rectangle(r)
print (clock.fps())

3
usr/examples/median.py Normal file
View File

@ -0,0 +1,3 @@
import sensor, time
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.snapshot().median(size=3)

View File

@ -1,11 +1,11 @@
import sensor, imlib, time
clock = time.clock()
import sensor, time
# Set sensor to grayscale
sensor.set_pixformat(sensor.GRAYSCALE)
clock = time.clock()
while (True):
image = sensor.snapshot()
clock.tick()
surf1 = imlib.surf_detector(image, False, 0.0008)
clock.tick()
kp = image.find_keypoints(upright=False, thresh=0.0004, octaves=2)
image.draw_keypoints(kp)
print (clock.avg())
imlib.surf_draw_ipts(image, surf1)

View File

@ -1,15 +1,19 @@
import sensor, imlib, time
clock = time.clock()
import sensor, time
# Set sensor gainceiling
sensor.set_gainceiling(16)
# Set sensor brightness
sensor.set_brightness(-2)
# Set sensor to grayscale
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_brightness(-2)
image = sensor.snapshot()
surf1 = imlib.surf_detector(image, False, 0.0004)
imlib.surf_draw_ipts(image, surf1)
kp = image.find_keypoints(upright=False, thresh=0.0004, octaves=2)
image.draw_keypoints(kp)
time.sleep(2000)
clock = time.clock()
while (True):
image = sensor.snapshot()
clock.tick()
surf2 = imlib.surf_detector(image, False, 0.0004)
imlib.surf_match(image, surf1, surf2)
ipts2 = image.find_keypoints_match(kp)
print (clock.avg())

View File

@ -0,0 +1,3 @@
import sensor, time
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.snapshot().save("0:/test.ppm", subimage=(0, 0, 10,10))