• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • roi does not overlap on the image?经常出现这个问题怎么回事啊?



    • roi does not overlap on the image?经常出现这个问题怎么回事啊!12345678



    • 如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片



    • 请# Untitled - By: A - 周六 10月 10 2020
      
      import sensor
      import image
      import 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()
      enable_lens_corr = False  # turn on for straighter lines...打开以获得更直的线条…
      
      
      thresholds = [(30, 100, 15, 127, 15, 127),  # 红
                    (68, 81, -90, -24, 19, 90),  # 绿
                    (28, 72, -7, 49, -103, -50)]  # 蓝
      
      # generic_red_thresholds -> index is 0 so code == (1 << 0)
      red = (30, 100, 15, 127, 15, 127)
      green = (0, 100, -94, -28, 22, 90)
      blue = (28, 72, -7, 49, -103, -50)
      
      if (sensor.get_id() == sensor.OV7725):
          sensor.__write_reg(0xAC, 0xDF)
          sensor.__write_reg(0x8F, 0xFF)
      
      
      min_degree = 0
      max_degree = 179
      
      
      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
      
      
      while(True):
          clock.tick()
          img = sensor.snapshot().lens_corr(1.8)
          img.gaussian(1, unsharp=True)
      
          # 下面的`threshold`应设置为足够高的值,以滤除在图像中检测到的具有
      
          # 低边缘幅度的噪声矩形。最适用与背景形成鲜明对比的矩形。
      
          # 检测正方形
          flag = 0    # 摄像头是否检测到物体
          for r in img.find_rects(threshold=3000):
      
              area = (r.x(), r.y(), r.h(), r.w())
              statistics = img.get_statistics (roi = area)  # 像素颜色统计
              m =(1/2)*r.w()
              n = (1/2)*r.h()
              # print(statistics)
      
              print(m,n)
      
              # (0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的矩形。
      
              # l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
      
              if 20 < statistics.l_mode() < 80 and -12 < statistics.a_mode() < 90 and 2 < statistics.b_mode() < 93:  # if the rectangle is red
                  img.draw_rectangle(r.rect(), color=(255, 0, 0))  # 识别到的红色矩形用红色的矩框出来
                  print('这是一个红色矩形')
                  m = int(m)
                  n = int(n)
                  img.draw_cross(r.x()+m, r.y() + n, size=5, color=(255,255,255))
                  flag = 1
      
              if 5 < statistics.l_mode() < 81 and -73 < statistics.a_mode() < 16 and 9 < statistics.b_mode() < 75:  # if the rectangle is red
                  img.draw_rectangle(r.rect(), color=(0, 255, 0))  # 识别到的绿色矩形用绿色的矩框出来
                  m = int(m)
                  n = int(n)
                  img.draw_cross(r.x()+m, r.y() + n, size=5, color=(255,255,255))
                  print('这是一个绿色矩形')
                  flag = 1
      
              if 28 < statistics.l_mode() < 72 and -7 < statistics.a_mode() < 49 and -103 < statistics.b_mode() < -50:  # if the rectangle is red
                  img.draw_rectangle(r.rect(), color=(0, 0, 255))  # 识别到的蓝色矩形用蓝色的矩框出来
                  m = int(m)
                  n = int(n)
                  img.draw_cross(r.x()+m, r.y() + n, size=5, color=(255,255,255))
                  print('这是一个蓝色矩形')
                  flag = 1
              # print(r)在这里粘贴代码
      

      0_1602476855746_QQ图片20201012122719.png

      0_1602476787735_17558c80-3798-4e49-bb57-90b74f93bf0b-image.png



    • 错误原因:find_rects返回的数值有时候是负数,导致错误。
      解决办法:在area = (r.x(), r.y(), r.h(), r.w())下面添加

              if r.x()<0 or r.y()<0:
                  continue
      

      可以跳过这次错误的结果。

      这个确实不应该出现,应该是固件的错误。我提交了issue,下次固件更新可以解决。https://github.com/openmv/openmv/issues/925



    • 为什么我采集三角形经常会让其他圆形或矩形来识别,总会混叠



    • @w3ks 新的问题单独发帖子