import sensor, image, time,json
from pyb import UART
i= 1
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green things. You may wish to tune them...
thresholds = [(7, 41, 13, 37, -63, -21), #yellow generic_red_thresholds -> index is 0 so code == (1 << 0)
(55, 79, -39, 0, 8, 27),
(35, 55, 21, 84, 26, 69)] #blue generic_green_thresholds -> index is 1 so code == (1 << 1)
# 当“find_blobs”的“merge = True”时,code代码被组合在一起。
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()
# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = True”合并图像中所有重叠的色块。
uart =UART(3,115200)
while(True):
clock.tick()
img = sensor.snapshot()
if i==1:
img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
for code in img.find_qrcodes():
print(code)
output_str="{%d}" code
uart.write(output_str+'\r\n')
print('send:',output_str)
i=1
else:
for blob in img.find_blobs(thresholds,pixels_threshold =50):
if blob.code() == 1: # r/g code == (1 << 1) | (1 << 0)
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
output_str="{1}"
uart.write(output_str+'\r\n')
print('send:',output_str)
if blob.code() == 2: # r/g code == (1 << 1) | (1 << 0)
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
output_str="{2}"
uart.write(output_str+'\r\n')
print('send:',output_str)
#print(2)
if blob.code() == 4: # r/g code == (1 << 1) | (1 << 0)
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
output_str="{3}"
uart.write(output_str+'\r\n')
print('send:',output_str)
#print(3)
|