logo

为什么无法找到黄色和青色的圆形????

2019-05-13 17:32
3
炗
7e874d68-b979-4152-8af5-51c517bb8bd5.PNG
import sensor, image, time

# The below thresholds track in general red/green things. You may wish to tune them...
#thresholds = [(49, 58, 64, 81, 12, 64), # generic_red_thresholds
              #(81, 93, -82, -40, 17, 74), # generic_green_thresholds
              #(60, 74, -13, 10, -63, -34),# generic_blue_thresholds
              #(90, 95, -56, -32, -21, 4),# generic_qing_thresholds
              #(80, 95, -21, 5, 34, 79),# generic_yellow_thresholds
              #(3, 18, -7, 15, -15, 7),# generic_black_thresholds
              #(60, 70, 30, 66, -64, -40) # generic_purple_thresholds
              
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    for c in img.find_circles(threshold = 2000, x_margin = 5, y_margin = 5, r_margin = 10,
            r_min = 5, r_max = 100, r_step = 2):
        area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
        #area为识别到的圆的区域,即圆的外接矩形框
        #img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        statistics = img.get_statistics(roi=area)#像素颜色统计
        print(statistics)
        #(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
        #l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
        if 49<statistics.l_mode()<58 and 65<statistics.a_mode()<81 and 12<statistics.b_mode()<64:#if the circle is red
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))#识别到的红色圆形用红色的圆框出来
        elif 81<statistics.l_mode()<93 and -82<statistics.a_mode()<-40 and 17<statistics.b_mode()<74:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        elif 60<statistics.l_mode()<74 and -13<statistics.a_mode()<10 and -63<statistics.b_mode()<-34:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        elif 90<statistics.l_mode()<95 and -56<statistics.a_mode()<-32 and -21<statistics.b_mode()<4:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        elif 80<statistics.l_mode()<95 and -21<statistics.a_mode()<5 and 31<statistics.b_mode()<79:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        elif 3<statistics.l_mode()<18 and -7<statistics.a_mode()<16 and -15<statistics.b_mode()<7:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
        elif 60<statistics.l_mode()<70 and 31<statistics.a_mode()<67 and -64<statistics.b_mode()<-40:
            img.draw_circle(c.x(), c.y(), c.r(), color = (0, 0, 0))
    print("FPS %f" % clock.fps())
2019-05-14 09:38
I
网红小智智 星瞳科技

如果你直接运行这个代码呢?

http://book.openmv.cc/example/09-Feature-Detection/find-circles.html

2019-05-14 10:33
3
炗

@kidswong999 就是直接运行那个代码可以找到其他圆但是就是找不到青色和黄色的两种圆我才设置阈值的哦

2019-05-15 00:15
I
网红小智智 星瞳科技

因为黄色的边缘不明显。threshold = 3500减小一点。

2019-05-15 09:59
3
炗

@kidswong999 我减小到1000了也是圈不出来哦。