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



    • 2_1560836694881_QQ截图20190618134312.png 1_1560836694880_QQ截图20190618134305.png 0_1560836694878_QQ截图20190618134252.png

      思路是先识别色块,然后在框内进行flood_fill的操作
      我想完成图1的效果,但是经常出现图2图3的样子

      我试过将flood_fill的(x,y)替换成色块识别的中心点,但是这样就没法填充了
      以下是代码:

      # 洪水填充
      #
      # 此示例显示图像中的洪水填充区域。
      import sensor, image, time
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
      sensor.set_framesize(sensor.QVGA) # or QQVGA...
      sensor.skip_frames(time = 2000)
      sensor.set_auto_whitebal(False);
      
      
      print("Learning thresholds...")
      threshold = (58, 91, 20, 60, -15, 18)
      
      
      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):
      
          # seed_threshold controls the maximum allowed difference between
          # the initial pixel and any filled pixels. It's important to
          # set this such that flood fill doesn't fill the whole image.
      
          # floating_threshold controls the maximum allowed difference
          # between any two pixels. This can easily fill the whole image
          # with even a very low threshold.
      
          # flood_fill will fill pixels that both thresholds.
      
          # You can invert what gets filled with "invert" and clear
          # everything but the filled area with "clear_background".
      
          #从中心点开始寻找,(x,y)即为Initial pixel
          x = sensor.width()//2
          y = sensor.height()//2
          img = sensor.snapshot()#从摄像头snapshot图像
          blobs=img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10)
          if blobs:
              #寻找最大物体
              max_blob=find_max(blobs)
              #设定ROI范围为最大物体的框
              roi=img.draw_rectangle(max_blob.rect())
              #在框中心点画十字
              img.draw_cross(max_blob.cx(), max_blob.cy())
              #x=max_blob.cx()
              #y=max_blob.cy()
              #在ROI中进行填充
              roi.flood_fill(x, y, seed_threshold=0.2, floating_thresholds=1, color=(255, 255, 0), invert=False, clear_background=False)
      


    • max_blob=find_max(blobs)
      img.flood_fill(max_blob.cx(), max_blob.cy(), seed_threshold=0.2, floating_thresholds=1, color=(255, 255, 0), invert=False, clear_background=False)
      


    • @kidswong999如何在色块识别的框的范围内进行颜色替换? 中说:

      max_blob=find_max(blobs)
      img.flood_fill(max_blob.cx(), max_blob.cy(), seed_threshold=0.2, floating_thresholds=1, color=(255, 255, 0), invert=False, clear_background=False)
      

      0_1560930374419_QQ截图20190619154549.png
      这我也试过了,这样就只有中心点是一个黄色的点,我是想把整个红色瓶盖换成别的颜色



    • img.flood_fill要在你画线画框函数的上面。看我的代码。



    • @kidswong999如何在色块识别的框的范围内进行颜色替换? 中说:

      img.flood_fill要在你画线画框函数的上面。看我的代码。

      搞定,谢谢