logo

can't convert str to int,咋解决呀?

2023-07-27 17:09
5
shuc
import sensor, image, time,math,pyb
from pyb import UART,LED
import json
import ustruct

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)

red_threshold_01=(10, 100, 127, 32, -43, 67)

clock = time.clock()

uart = UART(3,115200)
uart.init(115200, bits=8, parity=None, stop=1)

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

def sending_data(flag):
    global uart;
    data = ustruct.pack("<bbhb",
                   0x2C,
                   0x12,
                   str(flag),
                   0x5B)
    uart.write(data);

while(True):
    flag = 0
    clock.tick()
    img = sensor.snapshot()
    blobs = img.find_blobs([red_threshold_01])
    cx=0;cy=0;
    if blobs:
            max_b = find_max(blobs)
           
            cx=max_b[5]
            cy=max_b[6]
            cw=max_b[2]
            ch=max_b[3]
            flag = "red"
            
            img.draw_rectangle(max_b[0:4])
            img.draw_cross(max_b[5], max_b[6])
            FH = bytearray([0x2C,0x12,str(flag),0x5B])
            uart.write(FH)
            print(flag)
4fb26d7f-dc8b-4b88-8754-e30b4d98e1c5.png
2023-07-28 15:45
I
网红小智智 星瞳科技

你怎么能把"red"字符串当成bytearray发送呢?

2023-07-28 21:34
5
shuc

@kidswong999 l佬,我的想法是发送出去这个red字符串,那该去怎么改呀?

2023-07-28 21:48
5
shuc

@kidswong999 openmv与stm32通信识别到色块之后发送red这个字符串

2023-07-29 15:37
I
网红小智智 星瞳科技

既然发送字符串,又加0x2c, 0x12,0x5b做什么呢?你把设备的协议文档发上来。