• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 在形状被遮挡后识别颜色,环境改变后识别颜色怎么解决



    • import sensor, image, time, math
      
      # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
      # The below thresholds track in general red/green things. You may wish to tune them...
      thresholds = [(0, 20, -18, 127, -8, 22), # generic_red_thresholds -> index is 0 so code == (1 << 0)
                    (0, 60, -18, -48, 22, 127),
                    (0, 50, 2, 127, 2, 127)]  # generic_green_thresholds -> index is 1 so code == (1 << 1)
      # Codes are or'ed together when "merge=True" for "find_blobs".
      #roi=(20,20,20,20)
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.HQQVGA)
      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()
      # Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
      # returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
      # camera resolution. "merge=True" must be set to merge overlapping color blobs for color codes.
      def yanse():
                 for blob in img.find_blobs(thresholds, pixels_threshold=100, area_threshold=100, merge=True):
                     if blob.code() == 1: # r/g code == (1 << 1) | (1 << 0)
                        print("红色")
                        ys=0
                     elif blob.code() == 2: # r/g code == (1 << 1) | (1 << 0)
                        print("绿色")
                        ys=1
                     elif blob.code() == 4: # r/g code == (1 << 1) | (1 << 0)
                        print("黑色")
                        ys=2
                     else:
                         print("无色")
      while(True):
          clock.tick()
          img = sensor.snapshot()
          for r in img.find_rects(threshold = 1000):
              img.draw_rectangle(r.rect(), color = (255, 0, 0))
              roi1=r.rect()
              yanse()
              print("矩形")
              jx=1
              print("FPS %f" % clock.fps())
          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):
              img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
              roi1=(c.x(), c.y(), c.r())
              yanse()
              print("圆形")
              yx=2
      


    • 环境改变了,颜色肯定会变,把颜色阈值调大一些。



    • 要求是要加条件,进行判断如果环境改变,输出形状,如果形状被遮挡,输出颜色