我们想利用颜色形状同时识别的例程检测乒乓球,但效果并不好。请问大佬们有什么方法可以提高识别的精度呢。使用模块识别是不是可以提高精度呢?
是哪里效果不好,具体有什么问题?


当球后没有手时,可以识别;有手时不能识别。对环境要求太高了。有什么方法可以提高乒乓球的辨别率呢。
你的手,碰到了边缘,所以就不是圆了。
@yuan
import sensor, image, time
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
sensor.set_vflip(True)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,
r_min = 2, r_max = 100, r_step = 2):
area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
#area为识别到的圆的区域,即圆的外接矩形框
statistics = img.get_statistics(roi=area)#像素颜色统计
print(statistics)
#(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
#l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
if 0<statistics.l_mode()<100 and -17<statistics.a_mode()<38 and 40<statistics.b_mode()<92:#if the circle is red
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来
#judje = 1
#return true
#else:
#img.draw_rectangle(area, color = (255, 255, 255))
#将非红色的圆用白色的矩形框出来这是代码,我们把自动增益和白平衡关了和没关效果一样是怎么回事呢?
@kidswong999
没碰到它,只是在乒乓球的后面
应该是你阈值不对。你单独进行颜色识别,看一下能否把你的手识别进去。
单独进行颜色识别不会把手识别进去,阈值也正确
@yuan 单独进行颜色识别不会把手识别进去,阈值也正确
@konker 在 [怎样才能提高 颜色形状\(圆形\)同时识别 的精度](/post/4304) 中说:
> img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,
> r_min = 2, r_max = 100, r_step = 2):
改其中的3500,比如改成1500。
东方红吗?我想问一下识别到这个图形后怎么控制让车停下啊,谢谢您
@sagp 新的问题请发新帖提问。
识别到乒乓球后如何让UNO的一个管脚变为高电平啊?
@sagp 直接给管脚高电平,可以吧