examples: Format scripts.

This commit is contained in:
iabdalkader 2023-07-05 18:51:33 +02:00
parent 53fa4430be
commit 27404d6bd2
330 changed files with 4614 additions and 3303 deletions

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -10,13 +10,13 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()
@ -24,9 +24,7 @@ pyb.LED(BLUE_LED_PIN).on()
print("You're on camera!")
img = sensor.snapshot()
img.morph(1, [+2, +1, +0,\
+1, +1, -1,\
+0, -1, -2]) # Emboss the image.
img.morph(1, [+2, +1, +0, +1, +1, -1, +0, -1, -2]) # Emboss the image.
img.save("example.jpg") # or "example.bmp" (or others)

View File

@ -10,13 +10,13 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()

View File

@ -12,10 +12,10 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.HQVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.HQVGA) # Set frame size to HQVGA
sensor.skip_frames(time=2000) # Wait for settings take effect.
# Load up a face detection HaarCascade. This is object that your OpenMV Cam
# can use to detect faces using the find_features() method below. Your OpenMV
@ -25,18 +25,17 @@ sensor.skip_frames(time = 2000) # Let new settings take affect.
# stages.
face_cascade = image.HaarCascade("frontalface", stages=25)
while(True):
while True:
pyb.LED(RED_LED_PIN).on()
print("About to start detecting faces...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
print("Now detecting faces!")
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected a face after 10 frames.
while(diff):
while diff:
img = sensor.snapshot()
# Threshold can be between 0.0 and 1.0. A higher threshold results in a
# higher detection rate with more false positives. The scale value

View File

@ -12,19 +12,19 @@ import os
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
sensor.set_auto_whitebal(False) # Turn off white balance.
if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory
while(True):
if not "temp" in os.listdir():
os.mkdir("temp") # Make a temp directory
while True:
pyb.LED(RED_LED_PIN).on()
print("About to save background image...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
sensor.snapshot().save("temp/bg.bmp")
@ -32,14 +32,14 @@ while(True):
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected motion after 10 frames of motion.
while(diff):
while diff:
img = sensor.snapshot()
img.difference("temp/bg.bmp")
stats = img.statistics()
# Stats 5 is the max of the lighting color channel. The below code
# triggers when the lighting max for the whole image goes above 20.
# The lighting difference maximum should be zero normally.
if (stats[5] > 20):
if stats[5] > 20:
diff -= 1
pyb.LED(BLUE_LED_PIN).off()

View File

@ -19,8 +19,10 @@ rtc = pyb.RTC()
newFile = False
try:
os.stat('time.txt')
except OSError: # If the log file doesn't exist then set the RTC and set newFile to True
os.stat("time.txt")
except (
OSError
): # If the log file doesn't exist then set the RTC and set newFile to True
# datetime format: year, month, day, weekday (Monday=1, Sunday=7),
# hours (24 hour clock), minutes, seconds, subseconds (counds down from 255 to 0)
rtc.datetime((2018, 3, 9, 5, 13, 0, 0, 0))
@ -29,14 +31,16 @@ except OSError: # If the log file doesn't exist then set the RTC and set newFile
# Extract the date and time from the RTC object.
dateTime = rtc.datetime()
year = str(dateTime[0])
month = '%02d' % dateTime[1]
day = '%02d' % dateTime[2]
hour = '%02d' % dateTime[4]
minute = '%02d' % dateTime[5]
second = '%02d' % dateTime[6]
month = "%02d" % dateTime[1]
day = "%02d" % dateTime[2]
hour = "%02d" % dateTime[4]
minute = "%02d" % dateTime[5]
second = "%02d" % dateTime[6]
subSecond = str(dateTime[7])
newName='I'+year+month+day+hour+minute+second # Image file name based on RTC
newName = (
"I" + year + month + day + hour + minute + second
) # Image file name based on RTC
# Enable RTC interrupts every 10 seconds, camera will RESET after wakeup from deepsleep Mode.
rtc.wakeup(10000)
@ -46,24 +50,66 @@ BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time = 1000) # Let new settings take affect.
sensor.skip_frames(time=1000) # Let new settings take affect.
# Let folks know we are about to take a picture.
pyb.LED(BLUE_LED_PIN).on()
if(newFile): # If log file does not exist then create it.
with open('time.txt', 'a') as timeFile: # Write text file to keep track of date, time and image number.
timeFile.write('Date and time format: year, month, day, hours, minutes, seconds, subseconds' + '\n')
timeFile.write(newName + ',' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + subSecond + '\n')
if newFile: # If log file does not exist then create it.
with open(
"time.txt", "a"
) as timeFile: # Write text file to keep track of date, time and image number.
timeFile.write(
"Date and time format: year, month, day, hours, minutes, seconds, subseconds"
+ "\n"
)
timeFile.write(
newName
+ ","
+ year
+ ","
+ month
+ ","
+ day
+ ","
+ hour
+ ","
+ minute
+ ","
+ second
+ ","
+ subSecond
+ "\n"
)
else:
with open('time.txt', 'a') as timeFile: # Append to date, time and image number to text file.
timeFile.write(newName + ',' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + subSecond + '\n')
with open(
"time.txt", "a"
) as timeFile: # Append to date, time and image number to text file.
timeFile.write(
newName
+ ","
+ year
+ ","
+ month
+ ","
+ day
+ ","
+ hour
+ ","
+ minute
+ ","
+ second
+ ","
+ subSecond
+ "\n"
)
if not "images" in os.listdir(): os.mkdir("images") # Make a temp directory
if not "images" in os.listdir():
os.mkdir("images") # Make a temp directory
# Take photo and save to SD card
img = sensor.snapshot()
img.save('images/' + newName, quality=90)
img.save("images/" + newName, quality=90)
pyb.LED(BLUE_LED_PIN).off()
# Enter Deepsleep Mode (i.e. the OpenMV Cam effectively turns itself off except for the RTC).

View File

@ -14,14 +14,14 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()
@ -32,7 +32,7 @@ print("You're on camera!")
for i in range(100):
clock.tick()
# clock.avg() returns the milliseconds between frames - gif delay is in
g.add_frame(sensor.snapshot(), delay=int(clock.avg()/10)) # centiseconds.
g.add_frame(sensor.snapshot(), delay=int(clock.avg() / 10)) # centiseconds.
print(clock.fps())
g.close()

View File

@ -19,9 +19,9 @@ RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.
sensor.set_framesize(sensor.QQVGA) # or sensor.HQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
# Load up a face detection HaarCascade. This is object that your OpenMV Cam
# can use to detect faces using the find_features() method below. Your OpenMV
@ -31,18 +31,17 @@ sensor.skip_frames(time = 2000) # Let new settings take affect.
# stages.
face_cascade = image.HaarCascade("frontalface", stages=25)
while(True):
while True:
pyb.LED(RED_LED_PIN).on()
print("About to start detecting faces...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
print("Now detecting faces!")
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected a face after 10 frames.
while(diff):
while diff:
img = sensor.snapshot()
# Threshold can be between 0.0 and 1.0. A higher threshold results in a
# higher detection rate with more false positives. The scale value
@ -61,7 +60,7 @@ while(True):
for i in range(100):
clock.tick()
# clock.avg() returns the milliseconds between frames - gif delay is in
g.add_frame(sensor.snapshot(), delay=int(clock.avg()/10)) # centiseconds.
g.add_frame(sensor.snapshot(), delay=int(clock.avg() / 10)) # centiseconds.
print(clock.fps())
g.close()

View File

@ -18,19 +18,19 @@ import os
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
sensor.set_auto_whitebal(False) # Turn off white balance.
if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory
while(True):
if not "temp" in os.listdir():
os.mkdir("temp") # Make a temp directory
while True:
pyb.LED(RED_LED_PIN).on()
print("About to save background image...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
sensor.snapshot().save("temp/bg.bmp")
@ -38,14 +38,14 @@ while(True):
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected motion after 10 frames of motion.
while(diff):
while diff:
img = sensor.snapshot()
img.difference("temp/bg.bmp")
stats = img.statistics()
# Stats 5 is the max of the lighting color channel. The below code
# triggers when the lighting max for the whole image goes above 20.
# The lighting difference maximum should be zero normally.
if (stats[5] > 20):
if stats[5] > 20:
diff -= 1
g = gif.Gif("example-%d.gif" % pyb.rng(), loop=True)
@ -55,7 +55,7 @@ while(True):
for i in range(100):
clock.tick()
# clock.avg() returns the milliseconds between frames - gif delay is in
g.add_frame(sensor.snapshot(), delay=int(clock.avg()/10)) # centiseconds.
g.add_frame(sensor.snapshot(), delay=int(clock.avg() / 10)) # centiseconds.
print(clock.fps())
g.close()

View File

@ -9,13 +9,13 @@ import time
# Number of frames to pre-allocate and record
N_FRAMES = 500
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
# This frame size must match the image size passed to ImageIO
sensor.set_windowing((120, 120))
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
@ -27,7 +27,7 @@ for i in range(0, N_FRAMES):
stream.write(sensor.snapshot())
print(clock.fps())
while (True):
while True:
# Rewind stream and play back
stream.seek(0)
for i in range(0, N_FRAMES):

View File

@ -14,17 +14,17 @@ import time
snapshot_source = False # Set to true once finished to pull data from sensor.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
stream = None
if snapshot_source == False:
if snapshot_source is False:
stream = image.ImageIO("/stream.bin", "r")
while(True):
while True:
clock.tick()
if snapshot_source:
img = sensor.snapshot()

View File

@ -13,11 +13,11 @@ import time
record_time = 10000 # 10 seconds in milliseconds
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
stream = image.ImageIO("/stream.bin", "w")

View File

@ -15,14 +15,14 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()

View File

@ -19,10 +19,10 @@ import pyb
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.
sensor.set_framesize(sensor.QQVGA) # or sensor.HQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
# Load up a face detection HaarCascade. This is object that your OpenMV Cam
# can use to detect faces using the find_features() method below. Your OpenMV
@ -32,18 +32,17 @@ sensor.skip_frames(time = 2000) # Let new settings take affect.
# stages.
face_cascade = image.HaarCascade("frontalface", stages=25)
while(True):
while True:
pyb.LED(RED_LED_PIN).on()
print("About to start detecting faces...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
print("Now detecting faces!")
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected a face after 10 frames.
while(diff):
while diff:
img = sensor.snapshot()
# Threshold can be between 0.0 and 1.0. A higher threshold results in a
# higher detection rate with more false positives. The scale value

View File

@ -19,19 +19,19 @@ import os
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
sensor.set_auto_whitebal(False) # Turn off white balance.
if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory
while(True):
if not "temp" in os.listdir():
os.mkdir("temp") # Make a temp directory
while True:
pyb.LED(RED_LED_PIN).on()
print("About to save background image...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.skip_frames(time=2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
sensor.snapshot().save("temp/bg.bmp")
@ -39,14 +39,14 @@ while(True):
pyb.LED(BLUE_LED_PIN).on()
diff = 10 # We'll say we detected motion after 10 frames of motion.
while(diff):
while diff:
img = sensor.snapshot()
img.difference("temp/bg.bmp")
stats = img.statistics()
# Stats 5 is the max of the lighting color channel. The below code
# triggers when the lighting max for the whole image goes above 20.
# The lighting difference maximum should be zero normally.
if (stats[5] > 20):
if stats[5] > 20:
diff -= 1
m = mjpeg.Mjpeg("example-%d.mjpeg" % pyb.rng())

View File

@ -4,31 +4,31 @@
# rotation/scale by comparing the current and a previous
# image against each other. Note that only rotation/scale is
# handled - not X and Y translation in this mode.
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY rotate the camera around the lens and move the camera
# forward/backwards to see the numbers change.
# I.e. Z direction changes only.
import sensor
import time
import math
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B64X64 or B64X32 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
import math
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.B64X64) # Set frame size to 64x64... (or 64x32)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -38,19 +38,19 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
# This algorithm is hard to test without a perfect jig... So, here's a cheat to see it works.
# Put in a z_rotation value below and you should see the r output be equal to that.
if(0):
if 0:
expected_rotation = 20.0
img.rotation_corr(z_rotation=expected_rotation)
# This algorithm is hard to test without a perfect jig... So, here's a cheat to see it works.
# Put in a zoom value below and you should see the z output be equal to that.
if(0):
if 0:
expected_zoom = 0.8
img.rotation_corr(zoom=expected_zoom)
@ -61,9 +61,13 @@ while(True):
rotation_change = int(math.degrees(displacement.rotation()) * 5) / 5.0
zoom_amount = displacement.scale()
if(displacement.response() > 0.1): # Below 0.1 or so (YMMV) and the results are just noise.
print("{0:+f}r {1:+f}z {2} {3} FPS".format(rotation_change, zoom_amount, \
displacement.response(),
clock.fps()))
if (
displacement.response() > 0.1
): # Below 0.1 or so (YMMV) and the results are just noise.
print(
"{0:+f}r {1:+f}z {2} {3} FPS".format(
rotation_change, zoom_amount, displacement.response(), clock.fps()
)
)
else:
print(clock.fps())

View File

@ -4,30 +4,30 @@
# in the X and Y direction by comparing the current and a previous
# image against each other. Note that only X and Y translation is
# handled - not rotation/scale in this mode.
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY translate it to the left, right, up, and down and
# watch the numbers change. Note that you can see displacement numbers
# up +- half of the hoizontal and vertical resolution.
import sensor
import time
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B64X64 or B64X32 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.B64X64) # Set frame size to 64x64... (or 64x32)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -37,7 +37,7 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
@ -48,9 +48,13 @@ while(True):
sub_pixel_x = int(displacement.x_translation() * 5) / 5.0
sub_pixel_y = int(displacement.y_translation() * 5) / 5.0
if(displacement.response() > 0.1): # Below 0.1 or so (YMMV) and the results are just noise.
print("{0:+f}x {1:+f}y {2} {3} FPS".format(sub_pixel_x, sub_pixel_y,
displacement.response(),
clock.fps()))
if (
displacement.response() > 0.1
): # Below 0.1 or so (YMMV) and the results are just noise.
print(
"{0:+f}x {1:+f}y {2} {3} FPS".format(
sub_pixel_x, sub_pixel_y, displacement.response(), clock.fps()
)
)
else:
print(clock.fps())

View File

@ -4,31 +4,31 @@
# rotation/scale by comparing the current and the previous
# image against each other. Note that only rotation/scale is
# handled - not X and Y translation in this mode.
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY rotate the camera around the lens and move the camera
# forward/backwards to see the numbers change.
# I.e. Z direction changes only.
import sensor
import time
import math
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B64X64 or B64X32 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
import math
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.B64X64) # Set frame size to 64x64... (or 64x32)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -38,21 +38,21 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
# This algorithm is hard to test without a perfect jig... So, here's a cheat to see it works.
# Put in a z_rotation value below and you should see the r output be equal to that.
if(0):
if 0:
expected_rotation = 20.0
extra_fb.rotation_corr(z_rotation=(-expected_rotation))
# This algorithm is hard to test without a perfect jig... So, here's a cheat to see it works.
# Put in a zoom value below and you should see the z output be equal to that.
if(0):
if 0:
expected_zoom = 0.8
extra_fb.rotation_corr(zoom=(2.00-expected_zoom))
extra_fb.rotation_corr(zoom=(2.00 - expected_zoom))
displacement = extra_fb.find_displacement(img, logpolar=True)
extra_fb.replace(img)
@ -61,9 +61,13 @@ while(True):
rotation_change = int(math.degrees(displacement.rotation()) * 5) / 5.0
zoom_amount = displacement.scale()
if(displacement.response() > 0.1): # Below 0.1 or so (YMMV) and the results are just noise.
print("{0:+f}r {1:+f}z {2} {3} FPS".format(rotation_change, zoom_amount, \
displacement.response(),
clock.fps()))
if (
displacement.response() > 0.1
): # Below 0.1 or so (YMMV) and the results are just noise.
print(
"{0:+f}r {1:+f}z {2} {3} FPS".format(
rotation_change, zoom_amount, displacement.response(), clock.fps()
)
)
else:
print(clock.fps())

View File

@ -4,30 +4,30 @@
# in the X and Y direction by comparing the current and the previous
# image against each other. Note that only X and Y translation is
# handled - not rotation/scale in this mode.
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and QUICKLY translate it to the left, right, up, and down and
# watch the numbers change. Note that you can see displacement numbers
# up +- half of the hoizontal and vertical resolution.
import sensor
import time
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B64X64 or B64X32 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.B64X64) # Set frame size to 64x64... (or 64x32)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -37,7 +37,7 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
@ -48,9 +48,13 @@ while(True):
sub_pixel_x = int(displacement.x_translation() * 5) / 5.0
sub_pixel_y = int(displacement.y_translation() * 5) / 5.0
if(displacement.response() > 0.1): # Below 0.1 or so (YMMV) and the results are just noise.
print("{0:+f}x {1:+f}y {2} {3} FPS".format(sub_pixel_x, sub_pixel_y,
displacement.response(),
clock.fps()))
if (
displacement.response() > 0.1
): # Below 0.1 or so (YMMV) and the results are just noise.
print(
"{0:+f}x {1:+f}y {2} {3} FPS".format(
sub_pixel_x, sub_pixel_y, displacement.response(), clock.fps()
)
)
else:
print(clock.fps())

View File

@ -11,36 +11,34 @@
#
# NOTE that surfaces need to have some type of "edge" on them for the
# algorithm to work. A featureless surface produces crazy results.
# NOTE: Unless you have a very nice test rig this example is hard to see usefulness of...
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY rotate the camera around the lens and move the camera
# forward/backwards to see the numbers change.
# I.e. Z direction changes only.
import sensor
import time
import math
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B128X128 or B128X64 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
import math
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE (or RGB565)
sensor.set_framesize(sensor.B128X128) # Set frame size to 128x128... (or 128x64)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -50,26 +48,46 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.GRAYSCALE)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
for y in range(0, sensor.height(), BLOCK_H):
for x in range(0, sensor.width(), BLOCK_W):
# For this example we never update the old image to measure absolute change.
displacement = extra_fb.find_displacement(img, logpolar=True, \
roi = (x, y, BLOCK_W, BLOCK_H), template_roi = (x, y, BLOCK_W, BLOCK_H))
displacement = extra_fb.find_displacement(
img,
logpolar=True,
roi=(x, y, BLOCK_W, BLOCK_H),
template_roi=(x, y, BLOCK_W, BLOCK_H),
)
# Below 0.1 or so (YMMV) and the results are just noise.
if(displacement.response() > 0.1):
if displacement.response() > 0.1:
rotation_change = displacement.rotation()
zoom_amount = displacement.scale()
pixel_x = x + (BLOCK_W//2) + int(math.sin(rotation_change) * zoom_amount * (BLOCK_W//4))
pixel_y = y + (BLOCK_H//2) + int(math.cos(rotation_change) * zoom_amount * (BLOCK_H//4))
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, pixel_x, pixel_y), \
color = 255)
pixel_x = (
x
+ (BLOCK_W // 2)
+ int(math.sin(rotation_change) * zoom_amount * (BLOCK_W // 4))
)
pixel_y = (
y
+ (BLOCK_H // 2)
+ int(math.cos(rotation_change) * zoom_amount * (BLOCK_H // 4))
)
img.draw_line(
(x + BLOCK_W // 2, y + BLOCK_H // 2, pixel_x, pixel_y), color=255
)
else:
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, x + BLOCK_W//2, y + BLOCK_H//2), \
color = 0)
img.draw_line(
(
x + BLOCK_W // 2,
y + BLOCK_H // 2,
x + BLOCK_W // 2,
y + BLOCK_H // 2,
),
color=0,
)
print(clock.fps())

View File

@ -11,33 +11,33 @@
#
# NOTE that surfaces need to have some type of "edge" on them for the
# algorithm to work. A featureless surface produces crazy results.
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY translate it to the left, right, up, and down and
# watch the numbers change. Note that you can see displacement numbers
# up +- half of the hoizontal and vertical resolution.
import sensor
import time
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B128X128 or B128X64 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE (or RGB565)
sensor.set_framesize(sensor.B128X128) # Set frame size to 128x128... (or 128x64)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -47,24 +47,33 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.GRAYSCALE)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
for y in range(0, sensor.height(), BLOCK_H):
for x in range(0, sensor.width(), BLOCK_W):
# For this example we never update the old image to measure absolute change.
displacement = extra_fb.find_displacement(img, \
roi = (x, y, BLOCK_W, BLOCK_H), template_roi = (x, y, BLOCK_W, BLOCK_H))
displacement = extra_fb.find_displacement(
img, roi=(x, y, BLOCK_W, BLOCK_H), template_roi=(x, y, BLOCK_W, BLOCK_H)
)
# Below 0.1 or so (YMMV) and the results are just noise.
if(displacement.response() > 0.1):
pixel_x = x + (BLOCK_W//2) + int(displacement.x_translation())
pixel_y = y + (BLOCK_H//2) + int(displacement.y_translation())
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, pixel_x, pixel_y), \
color = 255)
if displacement.response() > 0.1:
pixel_x = x + (BLOCK_W // 2) + int(displacement.x_translation())
pixel_y = y + (BLOCK_H // 2) + int(displacement.y_translation())
img.draw_line(
(x + BLOCK_W // 2, y + BLOCK_H // 2, pixel_x, pixel_y), color=255
)
else:
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, x + BLOCK_W//2, y + BLOCK_H//2), \
color = 0)
img.draw_line(
(
x + BLOCK_W // 2,
y + BLOCK_H // 2,
x + BLOCK_W // 2,
y + BLOCK_H // 2,
),
color=0,
)
print(clock.fps())

View File

@ -11,36 +11,33 @@
#
# NOTE that surfaces need to have some type of "edge" on them for the
# algorithm to work. A featureless surface produces crazy results.
# NOTE: Unless you have a very nice test rig this example is hard to see usefulness of...
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY rotate the camera around the lens and move the camera
# forward/backwards to see the numbers change.
# I.e. Z direction changes only.
import sensor
import time
import math
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B128X128 or B128X64 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
import math
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE (or RGB565)
sensor.set_framesize(sensor.B128X128) # Set frame size to 128x128... (or 128x64)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -50,26 +47,46 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.GRAYSCALE)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
for y in range(0, sensor.height(), BLOCK_H):
for x in range(0, sensor.width(), BLOCK_W):
displacement = extra_fb.find_displacement(img, logpolar=True, \
roi = (x, y, BLOCK_W, BLOCK_H), template_roi = (x, y, BLOCK_W, BLOCK_H))
displacement = extra_fb.find_displacement(
img,
logpolar=True,
roi=(x, y, BLOCK_W, BLOCK_H),
template_roi=(x, y, BLOCK_W, BLOCK_H),
)
# Below 0.1 or so (YMMV) and the results are just noise.
if(displacement.response() > 0.1):
if displacement.response() > 0.1:
rotation_change = displacement.rotation()
zoom_amount = 1.0 + displacement.scale()
pixel_x = x + (BLOCK_W//2) + int(math.sin(rotation_change) * zoom_amount * (BLOCK_W//4))
pixel_y = y + (BLOCK_H//2) + int(math.cos(rotation_change) * zoom_amount * (BLOCK_H//4))
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, pixel_x, pixel_y), \
color = 255)
pixel_x = (
x
+ (BLOCK_W // 2)
+ int(math.sin(rotation_change) * zoom_amount * (BLOCK_W // 4))
)
pixel_y = (
y
+ (BLOCK_H // 2)
+ int(math.cos(rotation_change) * zoom_amount * (BLOCK_H // 4))
)
img.draw_line(
(x + BLOCK_W // 2, y + BLOCK_H // 2, pixel_x, pixel_y), color=255
)
else:
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, x + BLOCK_W//2, y + BLOCK_H//2), \
color = 0)
img.draw_line(
(
x + BLOCK_W // 2,
y + BLOCK_H // 2,
x + BLOCK_W // 2,
y + BLOCK_H // 2,
),
color=0,
)
extra_fb.replace(img)
print(clock.fps())

View File

@ -11,33 +11,32 @@
#
# NOTE that surfaces need to have some type of "edge" on them for the
# algorithm to work. A featureless surface produces crazy results.
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
#
# To run this demo effectively please mount your OpenMV Cam on a steady
# base and SLOWLY translate it to the left, right, up, and down and
# watch the numbers change. Note that you can see displacement numbers
# up +- half of the hoizontal and vertical resolution.
import sensor
import time
# NOTE!!! You have to use a small power of 2 resolution when using
#
# NOTE You have to use a small power of 2 resolution when using
# find_displacement(). This is because the algorithm is powered by
# something called phase correlation which does the image comparison
# using FFTs. A non-power of 2 resolution requires padding to a power
# of 2 which reduces the usefulness of the algorithm results. Please
# use a resolution like B128X128 or B128X64 (2x faster).
#
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
# it by doing "img.pool(2, 2)" on a 64x64 image.
import sensor
import time
BLOCK_W = 16 # pow2
BLOCK_H = 16 # pow2
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE (or RGB565)
sensor.set_framesize(sensor.B128X128) # Set frame size to 128x128... (or 128x64)...
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Take from the main frame buffer's RAM to allocate a second frame buffer.
@ -47,24 +46,33 @@ clock = time.clock() # Create a clock object to track the FPS.
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.GRAYSCALE)
extra_fb.replace(sensor.snapshot())
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
for y in range(0, sensor.height(), BLOCK_H):
for x in range(0, sensor.width(), BLOCK_W):
displacement = extra_fb.find_displacement(img, \
roi = (x, y, BLOCK_W, BLOCK_H), template_roi = (x, y, BLOCK_W, BLOCK_H))
displacement = extra_fb.find_displacement(
img, roi=(x, y, BLOCK_W, BLOCK_H), template_roi=(x, y, BLOCK_W, BLOCK_H)
)
# Below 0.1 or so (YMMV) and the results are just noise.
if(displacement.response() > 0.1):
pixel_x = x + (BLOCK_W//2) + int(displacement.x_translation())
pixel_y = y + (BLOCK_H//2) + int(displacement.y_translation())
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, pixel_x, pixel_y), \
color = 255)
if displacement.response() > 0.1:
pixel_x = x + (BLOCK_W // 2) + int(displacement.x_translation())
pixel_y = y + (BLOCK_H // 2) + int(displacement.y_translation())
img.draw_line(
(x + BLOCK_W // 2, y + BLOCK_H // 2, pixel_x, pixel_y), color=255
)
else:
img.draw_line((x + BLOCK_W//2, y + BLOCK_H//2, x + BLOCK_W//2, y + BLOCK_H//2), \
color = 0)
img.draw_line(
(
x + BLOCK_W // 2,
y + BLOCK_H // 2,
x + BLOCK_W // 2,
y + BLOCK_H // 2,
),
color=0,
)
extra_fb.replace(img)
print(clock.fps())

View File

@ -7,9 +7,9 @@ import sensor
import image
import time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
palette = image.Image(1, 256, sensor.RGB565)
@ -27,7 +27,7 @@ for i in range(192, 256):
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()

View File

@ -7,9 +7,9 @@ import sensor
import image
import time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
palette = image.Image(1, 256, sensor.RGB565)
@ -27,7 +27,7 @@ for i in range(192, 256):
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
@ -38,8 +38,9 @@ while(True):
# Cleanup noise.
img.erode(1)
blobs = img.find_blobs([(0, 0)], invert=True,
pixels_threshold=10, area_threshold=10, merge=False)
blobs = img.find_blobs(
[(0, 0)], invert=True, pixels_threshold=10, area_threshold=10, merge=False
)
for blob in blobs:
img.draw_rectangle(blob.rect(), color=(0, 255, 0))

View File

@ -17,13 +17,13 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120) - make smaller to go faster
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
sensor.set_auto_exposure(True, exposure_us=5000) # make smaller to go faster
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -18,12 +18,12 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(sensor.VGA) # Set frame size to VGA (640x480)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
sensor.ioctl(sensor.IOCTL_SET_TRIGGERED_MODE, True)
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -34,10 +34,20 @@ print("Resetting Lepton...")
sensor.reset()
# Enable measurement mode with high temp
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
@ -48,15 +58,29 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
def map_g_to_temp(g):
return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius
while(True):
def map_g_to_temp(g):
return (
(g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
) + min_temp_in_celsius
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect())
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
img.draw_string(blob.x(), blob.y() - 10, "%.2f C" % map_g_to_temp(stats.mean()), mono_space=False)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
img.draw_string(
blob.x(),
blob.y() - 10,
"%.2f C" % map_g_to_temp(stats.mean()),
mono_space=False,
)
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -31,10 +31,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
@ -45,15 +55,29 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
def map_g_to_temp(g):
return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius
while(True):
def map_g_to_temp(g):
return (
(g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
) + min_temp_in_celsius
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect())
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
img.draw_string(blob.x(), blob.y() - 10, "%.2f C" % map_g_to_temp(stats.mean()), mono_space=False)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
img.draw_string(
blob.x(),
blob.y() - 10,
"%.2f C" % map_g_to_temp(stats.mean()),
mono_space=False,
)
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -31,10 +31,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
@ -45,23 +55,43 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
def map_g_to_temp(g):
return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius
while(True):
def map_g_to_temp(g):
return (
(g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
) + min_temp_in_celsius
while True:
clock.tick()
img = sensor.snapshot()
blob_stats = []
blobs = img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True)
blobs = img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
)
# Collect stats into a list of tuples
for blob in blobs:
blob_stats.append((blob.x(), blob.y(), map_g_to_temp(img.get_statistics(thresholds=threshold_list,
roi=blob.rect()).mean())))
blob_stats.append(
(
blob.x(),
blob.y(),
map_g_to_temp(
img.get_statistics(
thresholds=threshold_list, roi=blob.rect()
).mean()
),
)
)
img.to_rainbow(color_palette=sensor.PALETTE_IRONBOW) # color it
# Draw stuff on the colored image
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
for blob_stat in blob_stats:
img.draw_string(blob_stat[0], blob_stat[1] - 10, "%.2f C" % blob_stat[2], mono_space=False)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
img.draw_string(
blob_stat[0], blob_stat[1] - 10, "%.2f C" % blob_stat[2], mono_space=False
)
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -32,10 +32,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.LCD)
@ -47,24 +57,44 @@ lcd.init()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
def map_g_to_temp(g):
return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius
while(True):
def map_g_to_temp(g):
return (
(g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
) + min_temp_in_celsius
while True:
clock.tick()
img = sensor.snapshot()
blob_stats = []
blobs = img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True)
blobs = img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
)
# Collect stats into a list of tuples
for blob in blobs:
blob_stats.append((blob.x(), blob.y(), map_g_to_temp(img.get_statistics(thresholds=threshold_list,
roi=blob.rect()).mean())))
blob_stats.append(
(
blob.x(),
blob.y(),
map_g_to_temp(
img.get_statistics(
thresholds=threshold_list, roi=blob.rect()
).mean()
),
)
)
img.to_rainbow(color_palette=sensor.PALETTE_IRONBOW) # color it
# Draw stuff on the colored image
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
for blob_stat in blob_stats:
img.draw_string(blob_stat[0], blob_stat[1] - 10, "%.2f C" % blob_stat[2], mono_space=False)
img.draw_string(
blob_stat[0], blob_stat[1] - 10, "%.2f C" % blob_stat[2], mono_space=False
)
lcd.display(img)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -32,10 +32,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.LCD)
@ -47,16 +57,30 @@ lcd.init()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
def map_g_to_temp(g):
return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius
while(True):
def map_g_to_temp(g):
return (
(g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
) + min_temp_in_celsius
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
stats = img.get_statistics(thresholds=threshold_list, roi=blob.rect())
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
img.draw_string(blob.x(), blob.y() - 10, "%.2f C" % map_g_to_temp(stats.mean()), mono_space=False)
img.draw_string(
blob.x(),
blob.y() - 10,
"%.2f C" % map_g_to_temp(stats.mean()),
mono_space=False,
)
lcd.display(img)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -16,9 +16,17 @@ threshold_list = [(220, 255)]
print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
@ -29,10 +37,12 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect(), color=127)
img.draw_cross(blob.cx(), blob.cy(), color=127)
print(clock.fps())

View File

@ -17,9 +17,17 @@ threshold_list = [(220, 255)]
print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.LCD)
@ -31,10 +39,12 @@ lcd.init()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect(), color=127)
img.draw_cross(blob.cx(), blob.cy(), color=127)
lcd.display(img)

View File

@ -11,14 +11,22 @@ import sensor
import time
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
threshold_list = [( 70, 100, -30, 40, 20, 100)]
threshold_list = [(70, 100, -30, 40, 20, 100)]
print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
# Make the color palette cool
sensor.set_color_palette(sensor.PALETTE_IRONBOW)
@ -31,10 +39,12 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print(clock.fps())

View File

@ -12,14 +12,22 @@ import time
import lcd
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
threshold_list = [( 70, 100, -30, 40, 20, 100)]
threshold_list = [(70, 100, -30, 40, 20, 100)]
print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
# Make the color palette cool
sensor.set_color_palette(sensor.PALETTE_IRONBOW)
@ -33,10 +41,12 @@ lcd.init()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
lcd.display(img)

View File

@ -31,10 +31,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
@ -45,10 +55,15 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect(), color=127)
img.draw_cross(blob.cx(), blob.cy(), color=127)
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -21,7 +21,7 @@ import sensor
import time
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
threshold_list = [( 70, 100, -30, 40, 20, 100)]
threshold_list = [(70, 100, -30, 40, 20, 100)]
# Set the target temp range here
min_temp_in_celsius = 20
@ -31,10 +31,20 @@ print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
sensor.ioctl(
sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius
)
print(
"Lepton Res (%dx%d)"
% (
sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT),
)
)
print(
"Radiometry Available: "
+ ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)
# Make the color palette cool
sensor.set_color_palette(sensor.PALETTE_IRONBOW)
@ -47,10 +57,15 @@ clock = time.clock()
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True):
for blob in img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE))
)

View File

@ -11,20 +11,25 @@ IMAGE_SCALE = 10 # Higher scaling uses more memory.
drawing_hint = image.BILINEAR # or image.BILINEAR or 0 (nearest neighbor)
# Initialize the ToF sensor
tof.init() #Auto-detects the connected sensor.
tof.init() # Auto-detects the connected sensor.
w = tof.width() * IMAGE_SCALE
h = tof.height() * IMAGE_SCALE
# FPS clock
clock = time.clock()
while (True):
while True:
clock.tick()
try:
img = tof.snapshot(x_size=w, y_size=h,
img = tof.snapshot(
x_size=w,
y_size=h,
color_palette=tof.PALETTE_IRONBOW,
hint=drawing_hint, copy_to_fb=True, scale=(0, 4000))
hint=drawing_hint,
copy_to_fb=True,
scale=(0, 4000),
)
except OSError:
continue

View File

@ -7,10 +7,10 @@ import image
import time
import tof
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((0, 0, 240, 240))
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((0, 0, 240, 240)) # Set window size to 240x240
# Initialize the ToF sensor
tof.init()
@ -18,7 +18,7 @@ tof.init()
# FPS clock
clock = time.clock()
while (True):
while True:
clock.tick()
# Capture an image
@ -31,12 +31,22 @@ while (True):
continue
# Scale the image and belnd it with the framebuffer
tof.draw_depth(img, depth, hint=image.BILINEAR,
alpha=200, scale=(0, 4000), color_palette=tof.PALETTE_IRONBOW)
tof.draw_depth(
img,
depth,
hint=image.BILINEAR,
alpha=200,
scale=(0, 4000),
color_palette=tof.PALETTE_IRONBOW,
)
# Draw min and max distance.
img.draw_string(8, 0, "Min distance: %d mm" % dmin, color = (255, 0, 0), mono_space = False)
img.draw_string(8, 8, "Max distance: %d mm" % dmax, color = (255, 0, 0), mono_space = False)
img.draw_string(
8, 0, "Min distance: %d mm" % dmin, color=(255, 0, 0), mono_space=False
)
img.draw_string(
8, 8, "Max distance: %d mm" % dmax, color=(255, 0, 0), mono_space=False
)
# Force high quality streaming
img.compress(quality=90)

View File

@ -30,17 +30,19 @@ sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
# The gain db ceiling maxes out at about 24 db for the OV7725 sensor.
sensor.set_auto_gain(True, gain_db_ceiling = 16.0) # Default gain.
sensor.set_auto_gain(True, gain_db_ceiling=16.0) # Default gain.
# Note! If you set the gain ceiling to low without adjusting the exposure control
# target value then you'll just get a lot of oscillation from the exposure
# control if it's on.
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print("FPS %f, Gain %f dB, Exposure %d us" % \
(clock.fps(), sensor.get_gain_db(), sensor.get_exposure_us()))
print(
"FPS %f, Gain %f dB, Exposure %d us"
% (clock.fps(), sensor.get_gain_db(), sensor.get_exposure_us())
)

View File

@ -28,7 +28,7 @@ sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
# Print out the initial exposure time for comparison.
print("Initial exposure == %d" % sensor.get_exposure_us())
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# You have to turn automatic gain control and automatic white blance off
@ -37,7 +37,7 @@ clock = time.clock() # Create a clock object to track the FPS.
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
# Need to let the above settings get in...
sensor.skip_frames(time = 500)
sensor.skip_frames(time=500)
current_exposure_time_in_microseconds = sensor.get_exposure_us()
print("Current Exposure == %d" % current_exposure_time_in_microseconds)
@ -45,8 +45,9 @@ print("Current Exposure == %d" % current_exposure_time_in_microseconds)
# Auto exposure control (AEC) is enabled by default. Calling the below function
# disables sensor auto exposure control. The additionally "exposure_us"
# argument then overrides the auto exposure value after AEC is disabled.
sensor.set_auto_exposure(False, \
exposure_us = int(current_exposure_time_in_microseconds * EXPOSURE_TIME_SCALE))
sensor.set_auto_exposure(
False, exposure_us=int(current_exposure_time_in_microseconds * EXPOSURE_TIME_SCALE)
)
print("New exposure == %d" % sensor.get_exposure_us())
# sensor.get_exposure_us() returns the exact camera sensor exposure time
@ -61,7 +62,7 @@ print("New exposure == %d" % sensor.get_exposure_us())
# Just disables the exposure value update but does not change the exposure
# value the camera sensor determined was good.
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -9,13 +9,13 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Change this to False to undo the mirror.
sensor.set_hmirror(True)
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -19,7 +19,7 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# You can control the white balance gains here. The first value is the
@ -33,8 +33,7 @@ clock = time.clock() # Create a clock object to track the FPS.
# comming out. Do not expect the exact value going in to be equal to the value
# comming out.
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps(), \
sensor.get_rgb_gain_db()) # Prints the AWB current RGB gains.
print(clock.fps(), sensor.get_rgb_gain_db()) # Prints the AWB current RGB gains.

View File

@ -9,13 +9,13 @@ import time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Change this to False to undo the flip.
sensor.set_vflip(True)
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -28,7 +28,7 @@ sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
# Print out the initial gain for comparison.
print("Initial gain == %f db" % sensor.get_gain_db())
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# You have to turn automatic exposure control and automatic white blance off
@ -37,7 +37,7 @@ clock = time.clock() # Create a clock object to track the FPS.
sensor.set_auto_exposure(False)
sensor.set_auto_whitebal(False)
# Need to let the above settings get in...
sensor.skip_frames(time = 500)
sensor.skip_frames(time=500)
current_gain_in_decibels = sensor.get_gain_db()
print("Current Gain == %f db" % current_gain_in_decibels)
@ -45,8 +45,7 @@ print("Current Gain == %f db" % current_gain_in_decibels)
# Auto gain control (AGC) is enabled by default. Calling the below function
# disables sensor auto gain control. The additionally "gain_db"
# argument then overrides the auto gain value after AGC is disabled.
sensor.set_auto_gain(False, \
gain_db = current_gain_in_decibels * GAIN_SCALE)
sensor.set_auto_gain(False, gain_db=current_gain_in_decibels * GAIN_SCALE)
print("New gain == %f db" % sensor.get_gain_db())
# sensor.get_gain_db() returns the exact camera sensor gain decibels.
@ -61,7 +60,7 @@ print("New gain == %f db" % sensor.get_gain_db())
# Just disables the gain value update but does not change the gain
# value the camera sensor determined was good.
while(True):
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

View File

@ -22,27 +22,29 @@ TRACKING_EDGE_TOLERANCE = 0.05 # Blob can move 5% away from the center.
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(SEARCHING_RESOLUTION)
sensor.skip_frames(time = 1000) # Wait for settings take effect.
sensor.skip_frames(time=1000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
sensor.set_auto_gain(False) # Turn off as it will oscillate.
sensor.set_auto_exposure(False, exposure_us=EXPOSURE_MICROSECONDS)
sensor.skip_frames(time = 1000)
sensor.skip_frames(time=1000)
# sensor_w and sensor_h are the image sensor raw pixels w/h (x/y are 0 initially).
x, y, sensor_w, sensor_h = sensor.ioctl(sensor.IOCTL_GET_READOUT_WINDOW)
while(True):
while True:
clock.tick()
img = sensor.snapshot()
# We need to find an IR object to track - it's likely to be really bright.
blobs = img.find_blobs(TRACKING_THRESHOLDS,
blobs = img.find_blobs(
TRACKING_THRESHOLDS,
area_threshold=SEARCHING_AREA_THRESHOLD,
pixels_threshold=SEARCHING_PIXEL_THRESHOLD)
pixels_threshold=SEARCHING_PIXEL_THRESHOLD,
)
if len(blobs):
most_dense_blob = max(blobs, key = lambda x: x.density())
most_dense_blob = max(blobs, key=lambda x: x.density())
img.draw_rectangle(most_dense_blob.rect())
def get_mapped_centroid(b):
@ -93,22 +95,28 @@ while(True):
x_error = x - new_x
y_error = y - new_y
if x_error < 0: print("-X Limit Reached ", end="")
if x_error > 0: print("+X Limit Reached ", end="")
if y_error < 0: print("-Y Limit Reached ", end="")
if y_error > 0: print("+Y Limit Reached ", end="")
if x_error < 0:
print("-X Limit Reached ", end="")
if x_error > 0:
print("+X Limit Reached ", end="")
if y_error < 0:
print("-Y Limit Reached ", end="")
if y_error > 0:
print("+Y Limit Reached ", end="")
center_on_blob(most_dense_blob, TRACKING_RESOLUTION)
# This loop will track the blob at a much higher readout speed and lower resolution.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
# Find the blob in the lower resolution image.
blobs = img.find_blobs(TRACKING_THRESHOLDS,
blobs = img.find_blobs(
TRACKING_THRESHOLDS,
area_threshold=TRACKING_AREA_THRESHOLD,
pixels_threshold=TRACKING_PIXEL_THRESHOLD)
pixels_threshold=TRACKING_PIXEL_THRESHOLD,
)
# If we loose the blob then we need to find a new one.
if not len(blobs):
@ -118,10 +126,12 @@ while(True):
break
# Narrow down the blob list and highlight the blob.
most_dense_blob = max(blobs, key = lambda x: x.density())
most_dense_blob = max(blobs, key=lambda x: x.density())
img.draw_rectangle(most_dense_blob.rect())
print(clock.fps(), "BLOB cx:%d, cy:%d" % get_mapped_centroid(most_dense_blob))
print(
clock.fps(), "BLOB cx:%d, cy:%d" % get_mapped_centroid(most_dense_blob)
)
x_diff = most_dense_blob.cx() - (sensor.width() / 2.0)
y_diff = most_dense_blob.cy() - (sensor.height() / 2.0)

View File

@ -13,23 +13,27 @@ EXPOSURE_MICROSECONDS = 20000
SEARCHING_RESOLUTION = sensor.QVGA
TRACKING_RESOLUTION = sensor.QQVGA # or sensor.QQQVGA
TRACKING_LOW_RATIO_THRESHOLD = 0.2 # Go to a smaller readout window when tag side vs res is smaller.
TRACKING_HIGH_RATIO_THRESHOLD = 0.8 # Go to a larger readout window when tag side vs res is larger.
TRACKING_LOW_RATIO_THRESHOLD = (
0.2 # Go to a smaller readout window when tag side vs res is smaller.
)
TRACKING_HIGH_RATIO_THRESHOLD = (
0.8 # Go to a larger readout window when tag side vs res is larger.
)
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(SEARCHING_RESOLUTION)
sensor.skip_frames(time = 1000) # Wait for settings take effect.
sensor.skip_frames(time=1000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
sensor.set_auto_gain(False) # Turn off as it will oscillate.
sensor.set_auto_exposure(False, exposure_us=EXPOSURE_MICROSECONDS)
sensor.skip_frames(time = 1000)
sensor.skip_frames(time=1000)
# sensor_w and sensor_h are the image sensor raw pixels w/h (x/y are 0 initially).
x, y, sensor_w, sensor_h = sensor.ioctl(sensor.IOCTL_GET_READOUT_WINDOW)
while(True):
while True:
clock.tick()
img = sensor.snapshot()
@ -37,7 +41,7 @@ while(True):
tags = img.find_apriltags()
if len(tags):
best_tag = max(tags, key = lambda x: x.decision_margin())
best_tag = max(tags, key=lambda x: x.decision_margin())
img.draw_rectangle(best_tag.rect())
# This needs to be less than the sensor output at default so we can move it around.
@ -94,17 +98,21 @@ while(True):
x_error = x - new_x
y_error = y - new_y
if x_error < 0: print("-X Limit Reached ", end="")
if x_error > 0: print("+X Limit Reached ", end="")
if y_error < 0: print("-Y Limit Reached ", end="")
if y_error > 0: print("+Y Limit Reached ", end="")
if x_error < 0:
print("-X Limit Reached ", end="")
if x_error > 0:
print("+X Limit Reached ", end="")
if y_error < 0:
print("-Y Limit Reached ", end="")
if y_error > 0:
print("+Y Limit Reached ", end="")
center_on_tag(best_tag, TRACKING_RESOLUTION)
loss_count = 0
# This loop will track the tag at a much higher readout speed and lower resolution.
while(True):
while True:
clock.tick()
img = sensor.snapshot()
@ -114,7 +122,7 @@ while(True):
# If we loose the tag then we need to find a new one.
if not len(tags):
# Handle a few bad frames due to tag flicker.
if (loss_count < 2):
if loss_count < 2:
loss_count += 1
continue
# Reset resolution.
@ -125,7 +133,7 @@ while(True):
loss_count = 0
# Narrow down the blob list and highlight the blob.
best_tag = max(tags, key = lambda x: x.decision_margin())
best_tag = max(tags, key=lambda x: x.decision_margin())
img.draw_rectangle(best_tag.rect())
print(clock.fps(), "TAG cx:%d, cy:%d" % get_mapped_centroid(best_tag))
@ -134,14 +142,18 @@ while(True):
h_ratio = best_tag.h() / sensor.height()
# Shrink the tracking window until the tag fits.
while (w_ratio < TRACKING_LOW_RATIO_THRESHOLD) or (h_ratio < TRACKING_LOW_RATIO_THRESHOLD):
while (w_ratio < TRACKING_LOW_RATIO_THRESHOLD) or (
h_ratio < TRACKING_LOW_RATIO_THRESHOLD
):
readout_window_w /= 2
readout_window_h /= 2
w_ratio *= 2
h_ratio *= 2
# Enlarge the tracking window until the tag fits.
while (TRACKING_HIGH_RATIO_THRESHOLD < w_ratio) or (TRACKING_HIGH_RATIO_THRESHOLD < h_ratio):
while (TRACKING_HIGH_RATIO_THRESHOLD < w_ratio) or (
TRACKING_HIGH_RATIO_THRESHOLD < h_ratio
):
readout_window_w *= 2
readout_window_h *= 2
w_ratio /= 2

View File

@ -9,25 +9,25 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x0 = (pyb.rng() % (2*img.width())) - (img.width()//2)
y0 = (pyb.rng() % (2*img.height())) - (img.height()//2)
x1 = (pyb.rng() % (2*img.width())) - (img.width()//2)
y1 = (pyb.rng() % (2*img.height())) - (img.height()//2)
x0 = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y0 = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
x1 = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y1 = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
# If the first argument is a scaler then this method expects
# to see x0, y0, x1, and y1. Otherwise, it expects a (x0,y0,x1,y1) tuple.
img.draw_arrow(x0, y0, x1, y1, color = (r, g, b), size = 30, thickness = 2)
img.draw_arrow(x0, y0, x1, y1, color=(r, g, b), size=30, thickness=2)
print(clock.fps())

View File

@ -9,18 +9,18 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
radius = pyb.rng() % (max(img.height(), img.width())//2)
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
radius = pyb.rng() % (max(img.height(), img.width()) // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
@ -28,6 +28,6 @@ while(True):
# If the first argument is a scaler then this method expects
# to see x, y, and radius. Otherwise, it expects a (x,y,radius) tuple.
img.draw_circle(x, y, radius, color = (r, g, b), thickness = 2, fill = False)
img.draw_circle(x, y, radius, color=(r, g, b), thickness=2, fill=False)
print(clock.fps())

View File

@ -9,23 +9,23 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
# If the first argument is a scaler then this method expects
# to see x and y. Otherwise, it expects a (x,y) tuple.
img.draw_cross(x, y, color = (r, g, b), size = 10, thickness = 2)
img.draw_cross(x, y, color=(r, g, b), size=10, thickness=2)
print(clock.fps())

View File

@ -9,19 +9,19 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
radius_x = pyb.rng() % (max(img.height(), img.width())//2)
radius_y = pyb.rng() % (max(img.height(), img.width())//2)
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
radius_x = pyb.rng() % (max(img.height(), img.width()) // 2)
radius_y = pyb.rng() % (max(img.height(), img.width()) // 2)
rot = pyb.rng()
r = (pyb.rng() % 127) + 128
@ -31,7 +31,8 @@ while(True):
# If the first argument is a scaler then this method expects
# to see x, y, radius x, and radius y.
# Otherwise, it expects a (x,y,radius_x,radius_y) tuple.
img.draw_ellipse(x, y, radius_x, radius_y, rot,
color = (r, g, b), thickness = 2, fill = False)
img.draw_ellipse(
x, y, radius_x, radius_y, rot, color=(r, g, b), thickness=2, fill=False
)
print(clock.fps())

View File

@ -8,10 +8,10 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
# seed_threshold controls the maximum allowed difference between
@ -29,8 +29,14 @@ while(True):
x = sensor.width() // 2
y = sensor.height() // 2
img = sensor.snapshot().flood_fill(x, y, \
seed_threshold=0.05, floating_thresholds=0.05, \
color=(255, 0, 0), invert=False, clear_background=False)
img = sensor.snapshot().flood_fill(
x,
y,
seed_threshold=0.05,
floating_thresholds=0.05,
color=(255, 0, 0),
invert=False,
clear_background=False,
)
print(clock.fps())

View File

@ -4,22 +4,21 @@
import sensor
import time
import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
small_img = img.mean_pooled(4, 4) # Makes a copy.
x = (img.width()//2)-(small_img.width()//2)
y = (img.height()//2)-(small_img.height()//2)
x = (img.width() // 2) - (small_img.width() // 2)
y = (img.height() // 2) - (small_img.height() // 2)
# Draws an image in the frame buffer.Pass an optional
# mask image to control what pixels are drawn.
img.draw_image(small_img, x, y, x_scale=1, y_scale=1)

View File

@ -5,12 +5,11 @@
import sensor
import image
import time
import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
BOUNCE = True
@ -44,7 +43,7 @@ ymin = -sensor.height() / SMALL_IMAGE_SCALE - 8
xmax = sensor.width() + 8
ymax = sensor.height() + 8
while(True):
while True:
clock.tick()
status = ""
@ -54,43 +53,66 @@ while(True):
# Makes a scaled copy of the sensor
small_img = img.mean_pooled(SMALL_IMAGE_SCALE, SMALL_IMAGE_SCALE)
status = 'rgb565 '
status = "rgb565 "
if CYCLE_FORMATS:
image_format = (value_mixer >> 8) & 3
# To test combining different formats
if (image_format==1): small_img = small_img.to_bitmap(copy=True); status = 'bitmap '
if (image_format==2): small_img = small_img.to_grayscale(copy=True); status = 'grayscale '
if (image_format==3): small_img = small_img.to_rgb565(copy=True); status = 'rgb565 '
if image_format == 1:
small_img = small_img.to_bitmap(copy=True)
status = "bitmap "
if image_format == 2:
small_img = small_img.to_grayscale(copy=True)
status = "grayscale "
if image_format == 3:
small_img = small_img.to_rgb565(copy=True)
status = "rgb565 "
# update small image location
if BOUNCE:
x = x + xd
if (x<xmin or x>xmax):
if x < xmin or x > xmax:
xd = -xd
y = y + yd
if (y<ymin or y>ymax):
if y < ymin or y > ymax:
yd = -yd
# Update small image scale
if RESCALE:
rescale = rescale + rd
if (rescale<min_rescale or rescale>max_rescale):
if rescale < min_rescale or rescale > max_rescale:
rd = -rd
# Find the center of the image
scaled_width = int(small_img.width() * abs(rescale))
scaled_height= int(small_img.height() * abs(rescale))
scaled_height = int(small_img.height() * abs(rescale))
apply_mask = CYCLE_MASK and ((value_mixer >> 9) & 1)
if apply_mask:
img.draw_image(small_img, int(x), int(y), mask=small_img.to_bitmap(copy=True), x_scale=rescale, y_scale=rescale, alpha=240, hint=image.BILINEAR | image.CENTER)
status += 'alpha:240 '
status += '+mask '
img.draw_image(
small_img,
int(x),
int(y),
mask=small_img.to_bitmap(copy=True),
x_scale=rescale,
y_scale=rescale,
alpha=240,
hint=image.BILINEAR | image.CENTER,
)
status += "alpha:240 "
status += "+mask "
else:
img.draw_image(small_img, int(x), int(y), x_scale=rescale, y_scale=rescale, alpha=128, hint=image.BILINEAR | image.CENTER)
status += 'alpha:128 '
img.draw_image(
small_img,
int(x),
int(y),
x_scale=rescale,
y_scale=rescale,
alpha=128,
hint=image.BILINEAR | image.CENTER,
)
status += "alpha:128 "
img.draw_string(8, 0, status, mono_space = False)
img.draw_string(8, 0, status, mono_space=False)
print(clock.fps())

View File

@ -21,53 +21,61 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
big_img = image.Image(128, 128, sensor.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
alpha_div = 1
alpha_value = 0
alpha_step = 2
x_bounce = sensor.width()//2
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
y_bounce = sensor.height()//2
y_bounce = sensor.height() // 2
y_bounce_toggle = 1
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
#img.to_grayscale()
#img.to_bitmap()
img.draw_image(big_img, x_bounce, y_bounce,
rgb_channel=-1, alpha=alpha_value//alpha_div,
hint=hint|image.CENTER)
# img.to_grayscale()
# img.to_bitmap()
img.draw_image(
big_img,
x_bounce,
y_bounce,
rgb_channel=-1,
alpha=alpha_value // alpha_div,
hint=hint | image.CENTER,
)
x_bounce += x_bounce_toggle
if abs(x_bounce-(img.width()//2)) >= (img.width()//2): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce - (img.width() // 2)) >= (img.width() // 2):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce-(img.height()//2)) >= (img.height()//2): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce - (img.height() // 2)) >= (img.height() // 2):
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value//alpha_div == 256: alpha_step = -alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -31,53 +31,62 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
big_img = image.Image(128, 128, sensor.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
alpha_div = 1
alpha_value = 0
alpha_step = 2
x_bounce = sensor.width()//2
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
y_bounce = sensor.height()//2
y_bounce = sensor.height() // 2
y_bounce_toggle = 1
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
#img.to_grayscale()
#img.to_bitmap()
img.draw_image(big_img, x_bounce, y_bounce,
rgb_channel=-1, alpha=alpha_value//alpha_div,
color_palette=sensor.PALETTE_IRONBOW, hint=hint|image.CENTER)
# img.to_grayscale()
# img.to_bitmap()
img.draw_image(
big_img,
x_bounce,
y_bounce,
rgb_channel=-1,
alpha=alpha_value // alpha_div,
color_palette=sensor.PALETTE_IRONBOW,
hint=hint | image.CENTER,
)
x_bounce += x_bounce_toggle
if abs(x_bounce-(img.width()//2)) >= (img.width()//2): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce - (img.width() // 2)) >= (img.width() // 2):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce-(img.height()//2)) >= (img.height()//2): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce - (img.height() // 2)) >= (img.height() // 2):
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value//alpha_div == 256: alpha_step = -alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -21,24 +21,24 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
big_img = image.Image(128, 128, sensor.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
alpha_lut = image.Image(256, 1, sensor.GRAYSCALE)
for i in range(256):
@ -48,30 +48,39 @@ alpha_div = 1
alpha_value = 0
alpha_step = 2
x_bounce = sensor.width()//2
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
y_bounce = sensor.height()//2
y_bounce = sensor.height() // 2
y_bounce_toggle = 1
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
#img.to_grayscale()
#img.to_bitmap()
img.draw_image(big_img, x_bounce, y_bounce,
rgb_channel=-1, alpha=alpha_value//alpha_div,
alpha_palette=alpha_lut, hint=hint|image.CENTER)
# img.to_grayscale()
# img.to_bitmap()
img.draw_image(
big_img,
x_bounce,
y_bounce,
rgb_channel=-1,
alpha=alpha_value // alpha_div,
alpha_palette=alpha_lut,
hint=hint | image.CENTER,
)
x_bounce += x_bounce_toggle
if abs(x_bounce-(img.width()//2)) >= (img.width()//2): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce - (img.width() // 2)) >= (img.width() // 2):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce-(img.height()//2)) >= (img.height()//2): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce - (img.height() // 2)) >= (img.height() // 2):
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value//alpha_div == 256: alpha_step = -alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -31,24 +31,24 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
big_img = image.Image(128, 128, sensor.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
alpha_lut = image.Image(256, 1, sensor.GRAYSCALE)
for i in range(256):
@ -58,30 +58,40 @@ alpha_div = 1
alpha_value = 0
alpha_step = 2
x_bounce = sensor.width()//2
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
y_bounce = sensor.height()//2
y_bounce = sensor.height() // 2
y_bounce_toggle = 1
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
#img.to_grayscale()
#img.to_bitmap()
img.draw_image(big_img, x_bounce, y_bounce,
rgb_channel=-1, alpha=alpha_value//alpha_div,
color_palette=sensor.PALETTE_IRONBOW, alpha_palette=alpha_lut, hint=hint|image.CENTER)
# img.to_grayscale()
# img.to_bitmap()
img.draw_image(
big_img,
x_bounce,
y_bounce,
rgb_channel=-1,
alpha=alpha_value // alpha_div,
color_palette=sensor.PALETTE_IRONBOW,
alpha_palette=alpha_lut,
hint=hint | image.CENTER,
)
x_bounce += x_bounce_toggle
if abs(x_bounce-(img.width()//2)) >= (img.width()//2): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce - (img.width() // 2)) >= (img.width() // 2):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce-(img.height()//2)) >= (img.height()//2): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce - (img.height() // 2)) >= (img.height() // 2):
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value//alpha_div == 256: alpha_step = -alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -17,8 +17,8 @@ down_hint = image.AREA # image.BILINEAR image.BICUBIC image.AREA
bounce_div = 128
medium_img = image.Image(32, 32, sensor.RGB565, copy_to_fb=True)
#medium_img.to_grayscale()
#medium_img.to_bitmap()
# medium_img.to_grayscale()
# medium_img.to_bitmap()
small_img = image.Image(4, 4, sensor.RGB565)
small_img.set_pixel(0, 0, (0, 0, 127))
@ -26,24 +26,24 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
big_img = image.Image(128, 128, sensor.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=up_hint)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
x_bounce = 0
x_bounce_toggle = 0
@ -52,20 +52,26 @@ y_bounce = 0
y_bounce_toggle = 0
clock = time.clock()
while(True):
while True:
clock.tick()
medium_img.clear()
medium_img.draw_image(big_img,
x_bounce // bounce_div, y_bounce // bounce_div,
x_scale=0.25, y_scale=0.25,
hint=down_hint)
medium_img.draw_image(
big_img,
x_bounce // bounce_div,
y_bounce // bounce_div,
x_scale=0.25,
y_scale=0.25,
hint=down_hint,
)
sensor.flush()
x_bounce += x_bounce_toggle
if abs(x_bounce // bounce_div) >= (medium_img.width()*1.1): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce // bounce_div) >= (medium_img.width() * 1.1):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce // bounce_div) >= (medium_img.height()*1.1): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce // bounce_div) >= (medium_img.height() * 1.1):
y_bounce_toggle = -y_bounce_toggle
print(clock.fps())

View File

@ -16,8 +16,8 @@ hint = 0 # image.BILINEAR image.BICUBIC
bounce_div = 32
big_img = image.Image(128, 128, sensor.RGB565, copy_to_fb=True)
#big_img.to_grayscale()
#big_img.to_bitmap()
# big_img.to_grayscale()
# big_img.to_bitmap()
small_img = image.Image(4, 4, sensor.RGB565)
small_img.set_pixel(0, 0, (0, 0, 127))
@ -25,19 +25,19 @@ small_img.set_pixel(1, 0, (47, 255, 199))
small_img.set_pixel(2, 0, (0, 188, 255))
small_img.set_pixel(3, 0, (0, 0, 127))
small_img.set_pixel(0, 1, (0, 176, 255))
small_img.set_pixel(1, 1, (222, 0, 0 ))
small_img.set_pixel(1, 1, (222, 0, 0))
small_img.set_pixel(2, 1, (50, 255, 195))
small_img.set_pixel(3, 1, (86, 255, 160))
small_img.set_pixel(0, 2, (255, 211, 0 ))
small_img.set_pixel(0, 2, (255, 211, 0))
small_img.set_pixel(1, 2, (83, 255, 163))
small_img.set_pixel(2, 2, (255, 211, 0))
small_img.set_pixel(3, 2, (0, 80, 255))
small_img.set_pixel(0, 3, (255, 118, 0 ))
small_img.set_pixel(1, 3, (127, 0, 0 ))
small_img.set_pixel(0, 3, (255, 118, 0))
small_img.set_pixel(1, 3, (127, 0, 0))
small_img.set_pixel(2, 3, (0, 144, 255))
small_img.set_pixel(3, 3, (50, 255, 195))
#small_img.to_grayscale()
#small_img.to_bitmap()
# small_img.to_grayscale()
# small_img.to_bitmap()
x_bounce = 0
x_bounce_toggle = 0
@ -46,20 +46,26 @@ y_bounce = 0
y_bounce_toggle = 0
clock = time.clock()
while(True):
while True:
clock.tick()
big_img.clear()
big_img.draw_image(small_img,
x_bounce // bounce_div, y_bounce // bounce_div,
x_scale=32, y_scale=32,
hint=hint)
big_img.draw_image(
small_img,
x_bounce // bounce_div,
y_bounce // bounce_div,
x_scale=32,
y_scale=32,
hint=hint,
)
sensor.flush()
x_bounce += x_bounce_toggle
if abs(x_bounce // bounce_div) >= (big_img.width()*1.1): x_bounce_toggle = -x_bounce_toggle
if abs(x_bounce // bounce_div) >= (big_img.width() * 1.1):
x_bounce_toggle = -x_bounce_toggle
y_bounce += y_bounce_toggle
if abs(y_bounce // bounce_div) >= (big_img.height()*1.1): y_bounce_toggle = -y_bounce_toggle
if abs(y_bounce // bounce_div) >= (big_img.height() * 1.1):
y_bounce_toggle = -y_bounce_toggle
print(clock.fps())

View File

@ -5,12 +5,11 @@
import sensor
import image
import time
import pyb
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE) # or GRAYSCALE...
sensor.set_framesize(sensor.QQVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
# the color palette is actually an image, this allows you to use image ops to create palettes
@ -23,11 +22,16 @@ for i, color in enumerate(palette_source_colors):
palette_source_color_image[i] = color
# Scale the image to palette width and smooth them
palette = image.Image(256,1, sensor.RGB565)
palette.draw_image(palette_source_color_image, 0, 0, x_scale=palette.width() / palette_source_color_image.width())
palette.mean(int(palette.width() / palette_source_color_image.width()/2))
palette = image.Image(256, 1, sensor.RGB565)
palette.draw_image(
palette_source_color_image,
0,
0,
x_scale=palette.width() / palette_source_color_image.width(),
)
palette.mean(int(palette.width() / palette_source_color_image.width() / 2))
while(True):
while True:
clock.tick()
img = sensor.snapshot()
@ -40,7 +44,20 @@ while(True):
palette_scale_x = (sensor.width() - palette_boundary_inset * 2) / palette.width()
img.draw_image(img_copy, 0, 0, color_palette=palette)
img.draw_image(palette, palette_boundary_inset, palette_boundary_inset, x_scale=palette_scale_x, y_scale=8)
img.draw_rectangle(palette_boundary_inset, palette_boundary_inset, int(palette.width()*palette_scale_x), 8, color=(255,255,255), thickness=1)
img.draw_image(
palette,
palette_boundary_inset,
palette_boundary_inset,
x_scale=palette_scale_x,
y_scale=8,
)
img.draw_rectangle(
palette_boundary_inset,
palette_boundary_inset,
int(palette.width() * palette_scale_x),
8,
color=(255, 255, 255),
thickness=1,
)
print(clock.fps())

View File

@ -10,17 +10,17 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(20):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
rot = pyb.rng() % 360
r = (pyb.rng() % 127) + 128
@ -28,6 +28,8 @@ while(True):
b = (pyb.rng() % 127) + 128
# This method draws a keypoints object or a list of (x, y, rot) tuples...
img.draw_keypoints([(x, y, rot)], color = (r, g, b), size = 20, thickness = 2, fill = False)
img.draw_keypoints(
[(x, y, rot)], color=(r, g, b), size=20, thickness=2, fill=False
)
print(clock.fps())

View File

@ -9,25 +9,25 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x0 = (pyb.rng() % (2*img.width())) - (img.width()//2)
y0 = (pyb.rng() % (2*img.height())) - (img.height()//2)
x1 = (pyb.rng() % (2*img.width())) - (img.width()//2)
y1 = (pyb.rng() % (2*img.height())) - (img.height()//2)
x0 = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y0 = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
x1 = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y1 = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
# If the first argument is a scaler then this method expects
# to see x0, y0, x1, and y1. Otherwise, it expects a (x0,y0,x1,y1) tuple.
img.draw_line(x0, y0, x1, y1, color = (r, g, b), thickness = 2)
img.draw_line(x0, y0, x1, y1, color=(r, g, b), thickness=2)
print(clock.fps())

View File

@ -9,25 +9,25 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
w = (pyb.rng() % (img.width()//2))
h = (pyb.rng() % (img.height()//2))
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
w = pyb.rng() % (img.width() // 2)
h = pyb.rng() % (img.height() // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
# If the first argument is a scaler then this method expects
# to see x, y, w, and h. Otherwise, it expects a (x,y,w,h) tuple.
img.draw_rectangle(x, y, w, h, color = (r, g, b), thickness = 2, fill = False)
img.draw_rectangle(x, y, w, h, color=(r, g, b), thickness=2, fill=False)
print(clock.fps())

View File

@ -9,17 +9,17 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
x = (pyb.rng() % (2 * img.width())) - (img.width() // 2)
y = (pyb.rng() % (2 * img.height())) - (img.height() // 2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
@ -28,8 +28,19 @@ while(True):
# to see x, y, and text. Otherwise, it expects a (x,y,text) tuple.
# Character and string rotation can be done at 0, 90, 180, 270, and etc. degrees.
img.draw_string(x, y, "Hello World!", color = (r, g, b), scale = 2, mono_space = False,
char_rotation = 0, char_hmirror = False, char_vflip = False,
string_rotation = 0, string_hmirror = False, string_vflip = False)
img.draw_string(
x,
y,
"Hello World!",
color=(r, g, b),
scale=2,
mono_space=False,
char_rotation=0,
char_hmirror=False,
char_vflip=False,
string_rotation=0,
string_hmirror=False,
string_vflip=False,
)
print(clock.fps())

View File

@ -12,10 +12,10 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
# A clip_limit of < 0 gives you normal adaptive histogram equalization

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -10,10 +10,10 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
# seed_threshold controls the maximum area growth of a colored

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -9,16 +9,15 @@ import time
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
# Use the Tools -> Machine Vision -> Threshold Edtor to pick better thresholds.
red_threshold = (0,100, 0,127, 0,127) # L A B
green_threshold = (0,100, -128,0, 0,127) # L A B
blue_threshold = (0,100, -128,127, -128,0) # L A B
while(True):
red_threshold = (0, 100, 0, 127, 0, 127) # L A B
green_threshold = (0, 100, -128, 0, 0, 127) # L A B
blue_threshold = (0, 100, -128, 127, -128, 0) # L A B
while True:
# Test red threshold
for i in range(100):
clock.tick()
@ -44,19 +43,19 @@ while(True):
for i in range(100):
clock.tick()
img = sensor.snapshot()
img.binary([red_threshold], invert = 1)
img.binary([red_threshold], invert=1)
print(clock.fps())
# Test not green threshold
for i in range(100):
clock.tick()
img = sensor.snapshot()
img.binary([green_threshold], invert = 1)
img.binary([green_threshold], invert=1)
print(clock.fps())
# Test not blue threshold
for i in range(100):
clock.tick()
img = sensor.snapshot()
img.binary([blue_threshold], invert = 1)
img.binary([blue_threshold], invert=1)
print(clock.fps())

View File

@ -13,12 +13,12 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
thresholds = (90, 100, -128, 127, -128, 127)
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().binary([thresholds], invert=False, zero=True)

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -4,7 +4,6 @@
# a binary image to remove noise. This example was originally a test but its
# useful for showing off how these functions work.
import pyb
import sensor
sensor.reset()
@ -13,8 +12,7 @@ sensor.set_framesize(sensor.QVGA)
grayscale_thres = (170, 255)
rgb565_thres = (70, 100, -128, 127, -128, 127)
while(True):
while True:
sensor.set_pixformat(sensor.GRAYSCALE)
for i in range(20):
img = sensor.snapshot()

View File

@ -9,14 +9,14 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
# Gamma, contrast, and brightness correction are applied to each color channel. The
# values are scaled to the range per color channel per image type...
img = sensor.snapshot().gamma_corr(gamma = 0.5, contrast = 1.0, brightness = 0.0)
img = sensor.snapshot().gamma_corr(gamma=0.5, contrast=1.0, brightness=0.0)
print(clock.fps())

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -9,14 +9,13 @@ import time
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
low_threshold = (0, 50)
high_threshold = (205, 255)
while(True):
while True:
# Test low threshold
for i in range(100):
clock.tick()
@ -35,12 +34,12 @@ while(True):
for i in range(100):
clock.tick()
img = sensor.snapshot()
img.binary([low_threshold], invert = 1)
img.binary([low_threshold], invert=1)
print(clock.fps())
# Test not high threshold
for i in range(100):
clock.tick()
img = sensor.snapshot()
img.binary([high_threshold], invert = 1)
img.binary([high_threshold], invert=1)
print(clock.fps())

View File

@ -13,12 +13,12 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
thresholds = (220, 255)
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().binary([thresholds], invert=False, zero=True)

View File

@ -9,10 +9,10 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot().histeq()

View File

@ -8,16 +8,14 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
kernel_size = 1 # 3x3==1, 5x5==2, 7x7==3, etc.
kernel = [-2, -1, 0, \
-1, 1, 1, \
0, 1, 2]
kernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2]
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -11,12 +11,12 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
while(True):
while True:
clock.tick()
img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)
img = sensor.snapshot().lens_corr(strength=1.8, zoom=1.0)
print(clock.fps())

View File

@ -11,10 +11,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().linpolar(reverse=False)

View File

@ -11,10 +11,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().logpolar(reverse=False)

View File

@ -10,10 +10,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -10,10 +10,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -10,10 +10,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -10,10 +10,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -10,10 +10,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -9,10 +9,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -11,10 +11,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -11,10 +11,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -9,10 +9,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().negate()

View File

@ -10,7 +10,7 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
# The image will be warped such that the following points become the new:
@ -28,10 +28,12 @@ clock = time.clock()
w = sensor.width()
h = sensor.height()
TARGET_POINTS = [(0, 0), # (x, y) CHANGE ME!
(w-1, 0), # (x, y) CHANGE ME!
(w-1, h-1), # (x, y) CHANGE ME!
(0, h-1)] # (x, y) CHANGE ME!
TARGET_POINTS = [
(0, 0), # (x, y) CHANGE ME!
(w - 1, 0), # (x, y) CHANGE ME!
(w - 1, h - 1), # (x, y) CHANGE ME!
(0, h - 1),
] # (x, y) CHANGE ME!
# Degrees per frame to rotation by...
X_ROTATION_DEGREE_RATE = 5
@ -42,28 +44,30 @@ Y_OFFSET = 0
ZOOM_AMOUNT = 1 # Lower zooms out - Higher zooms in.
FOV_WINDOW = 25 # Between 0 and 180. Represents the field-of-view of the scene
# window when rotating the image in 3D space. When closer to
# zero results in lines becoming straighter as the window
# moves away from the image being rotated in 3D space. A large
# value moves the window closer to the image in 3D space which
# results in the more perspective distortion and sometimes
# the image in 3D intersecting the scene window.
# window when rotating the image in 3D space. When closer to
# zero results in lines becoming straighter as the window
# moves away from the image being rotated in 3D space. A large
# value moves the window closer to the image in 3D space which
# results in the more perspective distortion and sometimes
# the image in 3D intersecting the scene window.
x_rotation_counter = 0
y_rotation_counter = 0
z_rotation_counter = 0
while(True):
while True:
clock.tick()
img = sensor.snapshot().rotation_corr(x_rotation = x_rotation_counter, \
y_rotation = y_rotation_counter, \
z_rotation = z_rotation_counter, \
x_translation = X_OFFSET, \
y_translation = Y_OFFSET, \
zoom = ZOOM_AMOUNT, \
fov = FOV_WINDOW, \
corners = TARGET_POINTS)
img = sensor.snapshot().rotation_corr(
x_rotation=x_rotation_counter,
y_rotation=y_rotation_counter,
z_rotation=z_rotation_counter,
x_translation=X_OFFSET,
y_translation=Y_OFFSET,
zoom=ZOOM_AMOUNT,
fov=FOV_WINDOW,
corners=TARGET_POINTS,
)
x_rotation_counter += X_ROTATION_DEGREE_RATE
y_rotation_counter += Y_ROTATION_DEGREE_RATE

View File

@ -9,7 +9,7 @@ import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
# The image will be warped such that the following points become the new:
@ -27,14 +27,16 @@ clock = time.clock()
w = sensor.width()
h = sensor.height()
TARGET_POINTS = [(0, 0), # (x, y) CHANGE ME!
(w-1, 0), # (x, y) CHANGE ME!
(w-1, h-1), # (x, y) CHANGE ME!
(0, h-1)] # (x, y) CHANGE ME!
TARGET_POINTS = [
(0, 0), # (x, y) CHANGE ME!
(w - 1, 0), # (x, y) CHANGE ME!
(w - 1, h - 1), # (x, y) CHANGE ME!
(0, h - 1),
] # (x, y) CHANGE ME!
while(True):
while True:
clock.tick()
img = sensor.snapshot().rotation_corr(corners = TARGET_POINTS)
img = sensor.snapshot().rotation_corr(corners=TARGET_POINTS)
print(clock.fps())

View File

@ -15,33 +15,35 @@ Y_OFFSET = 0
ZOOM_AMOUNT = 1 # Lower zooms out - Higher zooms in.
FOV_WINDOW = 60 # Between 0 and 180. Represents the field-of-view of the scene
# window when rotating the image in 3D space. When closer to
# zero results in lines becoming straighter as the window
# moves away from the image being rotated in 3D space. A large
# value moves the window closer to the image in 3D space which
# results in the more perspective distortion and sometimes
# the image in 3D intersecting the scene window.
# window when rotating the image in 3D space. When closer to
# zero results in lines becoming straighter as the window
# moves away from the image being rotated in 3D space. A large
# value moves the window closer to the image in 3D space which
# results in the more perspective distortion and sometimes
# the image in 3D intersecting the scene window.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
x_rotation_counter = 0
y_rotation_counter = 0
z_rotation_counter = 0
while(True):
while True:
clock.tick()
img = sensor.snapshot().rotation_corr(x_rotation = x_rotation_counter, \
y_rotation = y_rotation_counter, \
z_rotation = z_rotation_counter, \
x_translation = X_OFFSET, \
y_translation = Y_OFFSET, \
zoom = ZOOM_AMOUNT, \
fov = FOV_WINDOW)
img = sensor.snapshot().rotation_corr(
x_rotation=x_rotation_counter,
y_rotation=y_rotation_counter,
z_rotation=z_rotation_counter,
x_translation=X_OFFSET,
y_translation=Y_OFFSET,
zoom=ZOOM_AMOUNT,
fov=FOV_WINDOW,
)
x_rotation_counter += X_ROTATION_DEGREE_RATE
y_rotation_counter += Y_ROTATION_DEGREE_RATE

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -13,8 +13,7 @@ sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCA
sensor.set_framesize(sensor.QQVGA) # Set frame size to QVGA (320x240)
clock = time.clock() # Create a clock object to track the FPS.
while (True):
while True:
img = sensor.snapshot() # Take a picture and return the image.
a = np.array(img, dtype=np.uint8)
print("mean: %d std:%d"%(np.mean(a), np.std(a)))
print("mean: %d std:%d" % (np.mean(a), np.std(a)))

View File

@ -8,10 +8,10 @@ import time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.skip_frames(time=2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.

View File

@ -15,20 +15,22 @@ import pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
clock = time.clock()
mills = pyb.millis()
counter = 0
while(True):
while True:
clock.tick()
img = sensor.snapshot().replace(vflip=(counter//2)%2,
hmirror=(counter//4)%2,
transpose=(counter//8)%2)
img = sensor.snapshot().replace(
vflip=(counter // 2) % 2,
hmirror=(counter // 4) % 2,
transpose=(counter // 8) % 2,
)
if (pyb.millis() > (mills + 1000)):
if pyb.millis() > (mills + 1000):
mills = pyb.millis()
counter += 1

View File

@ -4,21 +4,26 @@
import sensor
import time
print("Letting auto algorithms run. Don't put anything in front of the camera!")
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()
# Capture the color thresholds for whatever was in the center of the image.
r = [(320//2)-(50//2), (240//2)-(50//2), 50, 50] # 50x50 center of QVGA.
r = [(320 // 2) - (50 // 2), (240 // 2) - (50 // 2), 50, 50] # 50x50 center of QVGA.
print("Auto algorithms done. Hold the object you want to track in front of the camera in the box.")
print("MAKE SURE THE COLOR OF THE OBJECT YOU WANT TO TRACK IS FULLY ENCLOSED BY THE BOX!")
print(
"Auto algorithms done. Hold the object you want to track in front of the camera in the box."
)
print(
"MAKE SURE THE COLOR OF THE OBJECT YOU WANT TO TRACK IS FULLY ENCLOSED BY THE BOX!"
)
for i in range(60):
img = sensor.snapshot()
img.draw_rectangle(r)
@ -28,12 +33,18 @@ threshold = [128, 128] # Middle grayscale values.
for i in range(60):
img = sensor.snapshot()
hist = img.get_histogram(roi=r)
lo = hist.get_percentile(0.01) # Get the CDF of the histogram at the 1% range (ADJUST AS NECESSARY)!
hi = hist.get_percentile(0.99) # Get the CDF of the histogram at the 99% range (ADJUST AS NECESSARY)!
lo = hist.get_percentile(
0.01
) # Get the CDF of the histogram at the 1% range (ADJUST AS NECESSARY)!
hi = hist.get_percentile(
0.99
) # Get the CDF of the histogram at the 99% range (ADJUST AS NECESSARY)!
# Average in percentile values.
threshold[0] = (threshold[0] + lo.value()) // 2
threshold[1] = (threshold[1] + hi.value()) // 2
for blob in img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
for blob in img.find_blobs(
[threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
img.draw_rectangle(r)
@ -41,10 +52,12 @@ for i in range(60):
print("Thresholds learned...")
print("Tracking colors...")
while(True):
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
for blob in img.find_blobs(
[threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print(clock.fps())

Some files were not shown because too many files have changed in this diff Show More