大佬能给出参考代码吗?
1
18281081004
@18281081004
0
声望
3
楼层
398
资料浏览
0
粉丝
0
关注
18281081004 发布的帖子
-
寻找最大的圆,黑色的,出错?
import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) 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() def find_max_c(areas): max_size = 0 for area in areas: if area.r() > max_size: max_area = area max_size = area.r() return max_area while(True): clock.tick() img = sensor.snapshot().lens_corr(1.8) for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2): areas = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r()) #area为识别到的圆的区域,即圆的外接矩形框 if areas: max_area = find_max_c(areas) statistics = img.get_statistics(roi=max_area)#像素颜色统计roi=areas #print(statistics) #(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。 #l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。 if 0<statistics.l_mode()<35 and -20<statistics.a_mode()<20 and -20<statistics.b_mode()<20:#if the circle is red img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的黑色圆形用红色的圆框出来 print("[%d,%d]" % (c.x(),c.y())) #方式1输出圆心坐标