@y26d 我的原贴里面就有代码呀,如果你是用我的原贴的代码的话你要根据你识别的圆形的颜色修改阈值哦
I
ivqk
@ivqk
0
声望
9
楼层
553
资料浏览
1
粉丝
0
关注
ivqk 发布的帖子
-
RE: 你的问题解决了吗?我的圆形都识别不出来,可以提供一下你的代码段吗
-
set_windowing设置ROI后显示出来的ROI区域扭曲?
import sensor, image, time,pyb ROI=(50,70,390,340) sensor.reset() # 初始化摄像头 sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565. sensor.set_framesize(sensor.VGA) sensor.set_windowing(ROI) sensor.skip_frames(10) # 跳过10帧,使新设置生效 sensor.set_auto_whitebal(False)# Create a clock object to track the FPS. clock = time.clock() while(True): img = sensor.snapshot() # Take a picture and return the image.
-
为什么无法找到黄色和青色的圆形????
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())