logo

圆识别不准确的问题,如何识别想要的圆

2024-04-28 11:29
H
大力士
from pyb import UART
import json

sensor.reset()  #摄像头初始化
sensor.set_pixformat(sensor.RGB565)  #设置为彩色模式
sensor.set_framesize(sensor.QQVGA)      #画幅为QQVGA即分辨率为160*120
sensor.skip_frames(time = 2000)         #跳过起始画面,获取稳定图像
sensor.set_auto_gain(False) #在色块检测模式下关闭自动补光
sensor.set_auto_whitebal(False) #关闭白平衡
clock = time.clock()

while(True):
    #lens_corr 为了去除畸变, 1.8 是默认参数,可以根据自己实际情况调整
#    img = sensor.snapshot().lens_corr(1.8)
    img = sensor.snapshot()
    # 圆形类有 4 个参数值: 圆心(x, y), r (半径)和 magnitude(量级);
    # 量级越大说明识别到的圆可信度越高。
    # `threshold` 参数控制找到圆的数量,数值的提升会降低识别圆形的总数。
    # `x_margin`, `y_margin`, and `r_margin`控制检测到接近圆的合并调节.
    # r_min, r_max, and r_step 用于指定测试圆的半径范围。
    for c in img.find_circles(threshold = 2500, x_margin = 10, y_margin
    = 10, r_margin = 10,r_min = 2, r_max = 20, r_step = 2):
        #画红色圆做指示
        img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
        print(c) #打印圆形的信息
image

如何识别自己想要的圆?

H
大力士
422023f2-6bc2-4c37-a3fd-a116d8b7259b.PNG