import sensor, image, time, math
from pyb import UART
import json
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()
uart = UART(3,115200) #定义串口3变量
def find_max(blobs): #定义寻找色块面积最大的函数
max_size=0
for blob in blobs:
if blob.pixels() > max_size:
max_blob=blob
max_size = blob.pixels()
return max_blob
####################################
#
#此为颜色处理代码
#
###################################
#bytearray为可变序列的字节数组 返回一个新的字节数组(将数据转为16进制)
img_data = bytearray([0x2C,18,X_black_Sign,Y_black_Sign,X_black_relative_displacement,Y_black_relative_displacement,
X_red_Sign,Y_red_Sign,X_red_relative_displacement,Y_red_relative_displacement,X_yellow_Sign,
Y_yellow_Sign,X_yellow_relative_displacement,Y_yellow_relative_displacement,
L_black,L_red,L_yellow,0x5B])
uart.write(img_data)
请在这里粘贴代码