mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
examples: Format scripts.
This commit is contained in:
parent
53fa4430be
commit
27404d6bd2
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
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
|
||||
|
||||
@ -10,10 +10,10 @@ 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.
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -10,10 +10,10 @@ 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.
|
||||
|
||||
@ -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,8 +25,7 @@ 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.
|
||||
@ -36,7 +35,7 @@ while(True):
|
||||
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
|
||||
|
||||
@ -12,16 +12,16 @@ 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.
|
||||
@ -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()
|
||||
|
||||
@ -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)
|
||||
@ -51,19 +55,61 @@ 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).
|
||||
|
||||
@ -14,11 +14,11 @@ 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.
|
||||
|
||||
@ -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,8 +31,7 @@ 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.
|
||||
@ -42,7 +41,7 @@ while(True):
|
||||
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
|
||||
|
||||
@ -18,16 +18,16 @@ 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.
|
||||
@ -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)
|
||||
|
||||
@ -9,9 +9,9 @@ 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))
|
||||
@ -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):
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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")
|
||||
|
||||
|
||||
@ -15,11 +15,11 @@ 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.
|
||||
|
||||
@ -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,8 +32,7 @@ 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.
|
||||
@ -43,7 +42,7 @@ while(True):
|
||||
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
|
||||
|
||||
@ -19,16 +19,16 @@ 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.
|
||||
@ -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())
|
||||
|
||||
@ -4,27 +4,27 @@
|
||||
# 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)...
|
||||
@ -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())
|
||||
|
||||
@ -4,26 +4,26 @@
|
||||
# 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)...
|
||||
@ -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())
|
||||
|
||||
@ -4,27 +4,27 @@
|
||||
# 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)...
|
||||
@ -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
|
||||
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))
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -4,26 +4,26 @@
|
||||
# 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)...
|
||||
@ -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())
|
||||
|
||||
@ -11,32 +11,30 @@
|
||||
#
|
||||
# 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)...
|
||||
@ -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())
|
||||
|
||||
@ -11,29 +11,29 @@
|
||||
#
|
||||
# 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)...
|
||||
@ -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):
|
||||
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)
|
||||
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())
|
||||
|
||||
@ -11,31 +11,28 @@
|
||||
#
|
||||
# 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)
|
||||
@ -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())
|
||||
|
||||
@ -11,28 +11,27 @@
|
||||
#
|
||||
# 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)
|
||||
@ -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):
|
||||
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)
|
||||
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())
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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.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
|
||||
|
||||
@ -23,7 +23,7 @@ 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
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -16,9 +16,17 @@ 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())
|
||||
|
||||
@ -17,9 +17,17 @@ 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)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -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))
|
||||
)
|
||||
|
||||
@ -18,13 +18,18 @@ 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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -39,8 +39,10 @@ sensor.set_auto_gain(True, gain_db_ceiling = 16.0) # Default gain.
|
||||
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())
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -15,7 +15,7 @@ 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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -15,7 +15,7 @@ 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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -32,14 +32,16 @@ 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())
|
||||
@ -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):
|
||||
@ -121,7 +129,9 @@ while(True):
|
||||
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)
|
||||
|
||||
@ -13,8 +13,12 @@ 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
|
||||
@ -29,7 +33,7 @@ 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()
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
@ -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())
|
||||
|
||||
@ -11,7 +11,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
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())
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
import sensor
|
||||
import time
|
||||
import pyb
|
||||
|
||||
sensor.reset()
|
||||
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
|
||||
@ -12,7 +11,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
import sensor
|
||||
import image
|
||||
import time
|
||||
import pyb
|
||||
|
||||
sensor.reset()
|
||||
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
|
||||
@ -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,28 +53,34 @@ 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
|
||||
@ -84,12 +89,29 @@ while(True):
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@ -51,23 +51,31 @@ 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.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())
|
||||
|
||||
@ -61,23 +61,32 @@ 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.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())
|
||||
|
||||
@ -55,23 +55,32 @@ 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.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())
|
||||
|
||||
@ -65,23 +65,33 @@ 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.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())
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
import sensor
|
||||
import image
|
||||
import time
|
||||
import pyb
|
||||
|
||||
sensor.reset()
|
||||
sensor.set_pixformat(sensor.GRAYSCALE) # or GRAYSCALE...
|
||||
@ -24,10 +23,15 @@ for i, color in enumerate(palette_source_colors):
|
||||
|
||||
# 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.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())
|
||||
|
||||
@ -13,7 +13,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
@ -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())
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
@ -20,8 +20,8 @@ while(True):
|
||||
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))
|
||||
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
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot()
|
||||
@ -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())
|
||||
|
||||
@ -15,7 +15,7 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
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
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ sensor.set_framesize(sensor.QVGA) # or QQVGA...
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
# seed_threshold controls the maximum area growth of a colored
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -17,8 +17,7 @@ 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):
|
||||
|
||||
while True:
|
||||
# Test red threshold
|
||||
for i in range(100):
|
||||
clock.tick()
|
||||
|
||||
@ -18,7 +18,7 @@ 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)
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA)
|
||||
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
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -15,8 +15,7 @@ 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()
|
||||
|
||||
@ -18,7 +18,7 @@ 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)
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.skip_frames(time=2000)
|
||||
clock = time.clock()
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot().histeq()
|
||||
|
||||
@ -13,11 +13,9 @@ 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.
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ sensor.set_framesize(sensor.QVGA)
|
||||
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)
|
||||
|
||||
@ -14,7 +14,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot().linpolar(reverse=False)
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot().logpolar(reverse=False)
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot().negate()
|
||||
|
||||
|
||||
@ -28,10 +28,12 @@ clock = time.clock()
|
||||
w = sensor.width()
|
||||
h = sensor.height()
|
||||
|
||||
TARGET_POINTS = [(0, 0), # (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!
|
||||
(0, h - 1),
|
||||
] # (x, y) CHANGE ME!
|
||||
|
||||
# Degrees per frame to rotation by...
|
||||
X_ROTATION_DEGREE_RATE = 5
|
||||
@ -53,17 +55,19 @@ 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
|
||||
|
||||
@ -27,12 +27,14 @@ clock = time.clock()
|
||||
w = sensor.width()
|
||||
h = sensor.height()
|
||||
|
||||
TARGET_POINTS = [(0, 0), # (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!
|
||||
(0, h - 1),
|
||||
] # (x, y) CHANGE ME!
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot().rotation_corr(corners=TARGET_POINTS)
|
||||
|
||||
@ -32,16 +32,18 @@ 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
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -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)))
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ 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.
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||
img = sensor.snapshot() # Take a picture and return the image.
|
||||
|
||||
|
||||
@ -21,14 +21,16 @@ clock = time.clock()
|
||||
mills = pyb.millis()
|
||||
counter = 0
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
clock.tick()
|
||||
|
||||
img = sensor.snapshot().replace(vflip=(counter//2)%2,
|
||||
img = sensor.snapshot().replace(
|
||||
vflip=(counter // 2) % 2,
|
||||
hmirror=(counter // 4) % 2,
|
||||
transpose=(counter//8)%2)
|
||||
transpose=(counter // 8) % 2,
|
||||
)
|
||||
|
||||
if (pyb.millis() > (mills + 1000)):
|
||||
if pyb.millis() > (mills + 1000):
|
||||
mills = pyb.millis()
|
||||
counter += 1
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
import sensor
|
||||
import time
|
||||
|
||||
print("Letting auto algorithms run. Don't put anything in front of the camera!")
|
||||
|
||||
sensor.reset()
|
||||
@ -17,8 +18,12 @@ 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.
|
||||
|
||||
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
Loading…
Reference in New Issue
Block a user