mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update Python examples
This commit is contained in:
parent
91099e9edc
commit
08a2e41167
5
usr/examples/blit_image.py
Normal file
5
usr/examples/blit_image.py
Normal 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)
|
||||||
@ -9,7 +9,7 @@ while (True):
|
|||||||
# detect blobs
|
# detect blobs
|
||||||
image.threshold((255, 127, 127), 40)
|
image.threshold((255, 127, 127), 40)
|
||||||
image.median(3)
|
image.median(3)
|
||||||
blobs = image.count_blobs()
|
blobs = image.find_blobs()
|
||||||
|
|
||||||
# draw rectangles around detected blobs
|
# draw rectangles around detected blobs
|
||||||
image = sensor.snapshot()
|
image = sensor.snapshot()
|
||||||
|
|||||||
8
usr/examples/circle.py
Normal file
8
usr/examples/circle.py
Normal 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)
|
||||||
@ -1,19 +1,19 @@
|
|||||||
import sensor, imlib, time
|
import sensor, time
|
||||||
# Set sensor gainceiling
|
# Set sensor gainceiling
|
||||||
sensor.set_gainceiling(sensor.X8)
|
sensor.set_gainceiling(16)
|
||||||
# Set sensor brightness
|
# Set sensor brightness
|
||||||
sensor.set_brightness(-2)
|
sensor.set_brightness(-2)
|
||||||
# Set sensor to grayscale
|
# Set sensor to grayscale
|
||||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
|
||||||
# Load Haar Cascade
|
# Load Haar Cascade
|
||||||
cascade = imlib.load_cascade("0:/frontalface_default.cascade")
|
cascade = HaarCascade("0:/frontalface_default.cascade")
|
||||||
print(cascade)
|
print(cascade)
|
||||||
clock = time.clock()
|
clock = time.clock()
|
||||||
while (True):
|
while (True):
|
||||||
clock.tick()
|
clock.tick()
|
||||||
image = sensor.snapshot()
|
image = sensor.snapshot()
|
||||||
objects = imlib.detect_objects(image, cascade)
|
objects = image.find_features(cascade)
|
||||||
for r in objects:
|
for r in objects:
|
||||||
imlib.draw_rectangle(image, r)
|
image.draw_rectangle(r)
|
||||||
print (clock.fps())
|
print (clock.fps())
|
||||||
|
|||||||
3
usr/examples/median.py
Normal file
3
usr/examples/median.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import sensor, time
|
||||||
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
sensor.snapshot().median(size=3)
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import sensor, imlib, time
|
import sensor, time
|
||||||
clock = time.clock()
|
|
||||||
# Set sensor to grayscale
|
# Set sensor to grayscale
|
||||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
|
||||||
|
clock = time.clock()
|
||||||
while (True):
|
while (True):
|
||||||
image = sensor.snapshot()
|
image = sensor.snapshot()
|
||||||
clock.tick()
|
clock.tick()
|
||||||
surf1 = imlib.surf_detector(image, False, 0.0008)
|
kp = image.find_keypoints(upright=False, thresh=0.0004, octaves=2)
|
||||||
|
image.draw_keypoints(kp)
|
||||||
print (clock.avg())
|
print (clock.avg())
|
||||||
imlib.surf_draw_ipts(image, surf1)
|
|
||||||
@ -1,15 +1,19 @@
|
|||||||
import sensor, imlib, time
|
import sensor, time
|
||||||
clock = time.clock()
|
# Set sensor gainceiling
|
||||||
|
sensor.set_gainceiling(16)
|
||||||
|
# Set sensor brightness
|
||||||
|
sensor.set_brightness(-2)
|
||||||
# Set sensor to grayscale
|
# Set sensor to grayscale
|
||||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
sensor.set_brightness(-2)
|
|
||||||
image = sensor.snapshot()
|
image = sensor.snapshot()
|
||||||
surf1 = imlib.surf_detector(image, False, 0.0004)
|
kp = image.find_keypoints(upright=False, thresh=0.0004, octaves=2)
|
||||||
imlib.surf_draw_ipts(image, surf1)
|
image.draw_keypoints(kp)
|
||||||
time.sleep(2000)
|
time.sleep(2000)
|
||||||
|
|
||||||
|
clock = time.clock()
|
||||||
while (True):
|
while (True):
|
||||||
image = sensor.snapshot()
|
image = sensor.snapshot()
|
||||||
clock.tick()
|
clock.tick()
|
||||||
surf2 = imlib.surf_detector(image, False, 0.0004)
|
ipts2 = image.find_keypoints_match(kp)
|
||||||
imlib.surf_match(image, surf1, surf2)
|
|
||||||
print (clock.avg())
|
print (clock.avg())
|
||||||
3
usr/examples/write_image.py
Normal file
3
usr/examples/write_image.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import sensor, time
|
||||||
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
sensor.snapshot().save("0:/test.ppm", subimage=(0, 0, 10,10))
|
||||||
Loading…
Reference in New Issue
Block a user