1.摄像头模拟灰度传感器
判断偏移程度方法
A.利用在摄像头某位置设置多个roi,在roi区域内使用find_blobs函数,返回面积,检测其里面的阈值有多少是有大面积红色的,在这个方块里面还可以加上函数筛除只占了点边的红色方块(彩色灰度都适用)
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor
import time,image
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.SIF) # Set frame size to sif (352x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
#(0, 14)
kk=[(25,120,30,30),(55,120,30,30),(85,120,30,30),(115,120,30,30),(145,120,30,30),(175,120,30,30),(205,120,30,30),(235,120,30,30),(265,120,30,30),(295,120,30,30)]
C=0
for i in kk[0:10]:
img.draw_rectangle(i,color=(255,255,255))
C=C+1
A=img.find_blobs([(0, 4, -49, 25, -76, 69)],roi=i)
E=0
F=0
if A:
for D in A:
E=D.area()+E
F=F+1
if E:
if E/F>400 :
print(C)
B.可以运用image.get_statistics(roi=你设定的几个区域)看roi区域内的像素平均值有没有在你想要检测的颜色范围之中(只适用于灰度模式)
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor
import time,image
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.SIF) # Set frame size to sif (352x240)
sensor.skip_frames(time=2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
while True:
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
#(0, 14)
kk=[(25,120,30,30),(55,120,30,30),(85,120,30,30),(115,120,30,30),(145,120,30,30),(175,120,30,30),(205,120,30,30),(235,120,30,30),(265,120,30,30),(295,120,30,30)]
C=0
for i in kk[0:10]:
img.draw_rectangle(i,color=(255,255,255))
C=C+1
A=img.get_statistics(roi=i)
if A:
B=A.mean()
if 70<B<80 :
print(C)
2.线性回归
3.利用找方块,取他们的均值