星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 为什么无法找到黄色和青色的圆形????



    • 0_1557739920901_捕获.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())
      
      




    • This post is deleted!


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



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



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