logo

怎样避开json实现传出多个圆坐标

2022-04-23 23:44
K
_2nc3
from machine import UART
import json, sensor, image, time

uart = UART(2, baudrate=115200)
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8)

    # Circle objects have four values: x, y, r (radius), and magnitude. The
    # magnitude is the strength of the detection of the circle. Higher is
    # better...

    # `threshold` controls how many circles are found. Increase its value
    # to decrease the number of circles detected...

    # `x_margin`, `y_margin`, and `r_margin` control the merging of similar
    # circles in the x, y, and r (radius) directions.

    # r_min, r_max, and r_step control what radiuses of circles are tested.
    # Shrinking the number of tested circle radiuses yields a big performance boost.
    circles = img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,
            r_min = 2, r_max = 100, r_step = 2)
    uart.write("111")
    if circles:
        print('sum :', len(circles))
        output_str = json.dumps(circles)
        for c in circles:
           img.draw_circle(c.x(), c.y())
        print('you send:',output_str)
        uart.write(output_str+'\n')
2022-04-25 20:05
I
网红小智智 星瞳科技

https://forum.singtown.com/topic/2133/如何将色块的中心坐标做成二进制包发送到串口上