@egxs 感谢您!
但是识别起来还是有点飘 会框到其他的地方
4oqs 发布的帖子
-
RE: 我想要将颜色识别、形状识别、测距三种融合在一起可以实现吗?
那我现在应该怎么修改呢?
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 clock = time.clock() K=5000#the value should be measured yellow_threshold = (94, 100, -128, 127, -128, 127) while(True): clock.tick() img = sensor.snapshot().lens_corr(1.8) sensor.set_hmirror(True) #水平方向翻转 sensor.set_vflip(True) #垂直方向翻转 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) #(94, 100, -128, 127, -128, 127)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。 #l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。 if 94<statistics.l_mode()<100 and -128<statistics.a_mode()<127 and -128<statistics.b_mode()<127:#if the circle is red img.draw_rectangle(area, color = (255, 255, 255)) #将非红色的圆用白色的矩形框出来 def find_max(blobs): #识别最大色块 max_size=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob blobs = img.find_blobs([yellow_threshold]) if len(blobs) == 1: # Draw a rect around the blob. b = blobs[0] img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy Lm = (b[2]+b[3])/2 length = K/Lm print(Lm)
这是我重新修改的 还是实现不了 麻烦您指教
-
我想要将颜色识别、形状识别、测距三种融合在一起可以实现吗?
一下是我根据例程结合的 但是实现不了功能
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() K=5000#the value should be measured yellow_threshold = ( 56, 83, 5, 57, 63, 80) 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) #(94, 100, -128, 127, -128, 127)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。 #l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。 if 94<statistics.l_mode()<100 and -128<statistics.a_mode()<127 and -128<statistics.b_mode()<127:#if the circle is red img.draw_rectangle(area, color = (255, 255, 255)) #将非红色的圆用白色的矩形框出来 blobs = img.find_blobs([yellow_threshold]) if len(blobs) == 1: # Draw a rect around the blob. b = blobs[0] img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy Lm = (b[2]+b[3])/2 length = K/Lm print(Lm)