求问如何将这种坐标值来传输进32单片机里面进行通信?不使用字典
-
from machine import Pin
from pyb import UART
import sensor, image, time,math,pyb
#import seekfree, pyb
import pybimport json
import ustructlaser_light=Pin("P9", Pin.OUT)
laser_light.value(1)#lcd = seekfree.LCD180(3)
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 设置图像色彩格式为RGB565格式
sensor.set_framesize(sensor.QQVGA) # 设置图像大小为160*120
sensor.set_auto_whitebal(True) # 设置自动白平衡
sensor.set_brightness(3000) # 设置亮度为3000
sensor.skip_frames(time = 20) # 跳过帧
sensor.set_auto_gain(False)clock = time.clock()
corner = 0uart = UART(3,115200)
uart.init(115200, bits=8, parity=None, stop=1)def sending_data(corner1_str,corner2_str,corner3_str,corner4_str):
global uart;
data = ustruct.pack("<bbhhhhb",
0x2C,
0x12,
str(corner1_str),
str(corner2_str),
str(corner3_str),
str(corner4_str),
0x5B)
uart.write(data);while(True):
clock.tick()
img = sensor.snapshot()# 在图像中寻找矩形 for r in img.find_rects(threshold = 10000): # 判断矩形边长是否符合要求 if r.w() > 20 and r.h() > 20: # 在屏幕上框出矩形 img.draw_rectangle(r.rect(), color = (255, 0, 0), scale = 4) # 获取矩形角点位置 corner = r.corners() # 在屏幕上圈出矩形角点 img.draw_circle(corner[0][0], corner[0][1], 5, color = (0, 0, 255), thickness = 2, fill = False) img.draw_circle(corner[1][0], corner[1][1], 5, color = (0, 0, 255), thickness = 2, fill = False) img.draw_circle(corner[2][0], corner[2][1], 5, color = (0, 0, 255), thickness = 2, fill = False) img.draw_circle(corner[3][0], corner[3][1], 5, color = (0, 0, 255), thickness = 2, fill = False) corner4_str = f"corner4 = ({corner[0][0]},{corner[0][1]})" corner3_str = f"corner3 = ({corner[1][0]},{corner[1][1]})" corner2_str = f"corner2 = ({corner[2][0]},{corner[2][1]})" corner1_str = f"corner1 = ({corner[3][0]},{corner[3][1]})" data = bytearray([0x2C,0x12,corner1_str,corner2_str,corner3_str,corner4_str,0x5B]) uart.write(data) print(corner1_str + "\n" + corner2_str + "\n" + corner3_str + "\n" + corner4_str) # 设置激光颜色阈值 red_td = [(56, 100, 45, 127, -128, 127)] # 根据阈值找到色块 for b in img.find_blobs(red_td,pixels_threshold=2, area_threshold=15, merge=True,invert = 0): # 在屏幕上画出色块 img.draw_rectangle(b.rect(), color = (0, 255, 0), scale = 2, thickness = 2) print(f"rect = {b.x() + b.w()/2},{b.y() + b.h()/2}")
-
这里面也要咋去修改呀
-
@shuc 在 求问如何将这种坐标值来传输进32单片机里面进行通信?不使用字典 中说:
这里面也要咋去修改呀,换成列表list吗
-
如果你要发送二进制的格式,就不要用字符串了