logo

部分代码,为什么电脑接收不到圆的坐标?

2023-03-31 16:54
J
_4p3d
uart = UART(3, 115200)
    for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2):
        img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
        print(c)

    print("FPS %f" % clock.fps())

uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
def send_data_packet(x,y,z,w):
    #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
    #data = bytearray(frame)

    data = ustruct.pack("<bbhhhhb",      #格式为俩个字符俩个短整型(2字节)
                   0x2C,                      #帧头1
                   0x12,                      #帧头2
                   int(cx), # up sample by 4   #数据1
                   int(cy), # up sample by 4    #数据2
                   int(cw), # up sample by 4    #数据1
                   int(ch), # up sample by 4    #数据2
                   0x5B)
    uart.write(data);data_out = json.dumps(set(data))
       


while(True):
    clock.tick()
    date=bytearray[(1,2,3,4,5)]
    uart.write(data)

    img = sensor.snapshot()
    c = img.find_circles()
    cx=0;cy=0;
    if c:
         c = find_circles(c)

         cx=c.x()
         cy=c.y()
         cw=c.r()
         ch=c.magnitude()
         img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
         FH = bytearray([0x2C,0x12,cx,cy,cw,ch,0x5B])
            #sending_data(cx,cy,cw,ch)
         uart.write(FH)
         print(cx,cy,cw,ch)

请在这里粘贴代码

2023-03-31 18:24
I
网红小智智 星瞳科技

电脑端什么都没接到,还是格式错误?

2023-04-01 11:08
J
_4p3d

这个是识别到了圆,串行终端有代码输出,就是通过串口发不到电脑上

2023-04-03 20:26
I
网红小智智 星瞳科技

先用这个代码测试:

https://book.openmv.cc/example/02-Board-Control/uart-control.html

2023-04-05 13:01
J
_4p3d

这个代码能发出来

2023-04-05 20:23
I
网红小智智 星瞳科技
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
def send_data_packet(x,y,z,w):
    #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
    #data = bytearray(frame)

    data = ustruct.pack("<bbhhhhb",      #格式为俩个字符俩个短整型(2字节)
                   0x2C,                      #帧头1
                   0x12,                      #帧头2
                   int(cx), # up sample by 4   #数据1
                   int(cy), # up sample by 4    #数据2
                   int(cw), # up sample by 4    #数据1
                   int(ch), # up sample by 4    #数据2
                   0x5B)
    uart.write(data);data_out = json.dumps(set(data))
      
while(True):
    clock.tick()
    date=bytearray[(1,2,3,4,5)]
    uart.write(data)
    time.sleep(1)

运行这个测试。