# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor, image, time
from pyb import UART
def angle_rho_print(line_in):
if line_in.theta()>90:
angle=line_in.theta()-180
else:
angle=line_in.theta()
rho_err=abs(line_in.rho())-160
print("angle=",angle)
print("rho_err=",rho_err)
uart = UART(3, 115200, timeout_char=1000)
#low_threshold=(220,255)
low_threshold=(0, 100, -127, -15, -13, 63)
ROI_QVGA=(120,20,120,200)
ROI_QQVGA=(60,10,60,100)
sensor.reset() # Reset and initialize the sensor.
#sensor.set_vflip(True) #水平方向翻转
#sensor.set_hmirror(True) #垂直方向翻转
#sensor.set_pixformat(sensor.GRAYSCALE)#设置像素模式,GRAYSCALE:灰度,RGB565:彩色
sensor.set_pixformat(sensor.RGB565)#设置像素模式,GRAYSCALE:灰度,RGB565:彩色
sensor.set_framesize(sensor.QQVGA) # 设置像素大小:SVGA: 800x600 VGA: 640x480 QQQVGA:80x60
#QVGA: 320x240 QQVGA: 160x120
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.
img.binary([low_threshold])
#line = img.get_regression([low_threshold],False,robust = True)
line = img.get_regression([(100,100)], robust = True)
if (line):
img.draw_line(line.line(), color = 127)
#if uart.any():
data=uart.readline()
if line.theta()>90:
angle=line.theta()-180
else:
angle=line.theta()
rho_err=abs(line.rho())-160
out_str="[%d,%d]"%(angle,rho_err)
#uart.write(out_str)
print("angle=",angle)
print("rho_err=",rho_err)
print("帧率=",clock.fps())