logo

我在uart.write(c[0].x,c[1].x等等点)时会报错,让我不要加[],

2022-06-03 13:42
K
_2nc3

是这样的,但我在uart.write(c[0].x,c[1].x等等点)时会报错,让我不要加[],这怎样解决

2022-06-03 13:48
K
_2nc3
531823e5-7ea9-431a-881e-135af450c63e.png

像这样

2022-06-03 15:41
K
_2nc3
import sensor, image, time, pyb

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.

    for circles in img.find_circles(threshold = 2000, 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))
        c0=circles[0].x()
        print(c0)

最后就会显示AttributeError: 'int' object has no attribute 'x'

2022-06-06 20:12
I
网红小智智 星瞳科技

正确的代码:

import sensor, image, time, pyb

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)

    circles = img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,
            r_min = 2, r_max = 100, r_step = 2)
      
    for c in circles:
        img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
      
    if len(circles) > 0:
        c0=circles[0].x()
        print(c0)