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



    • # Multi Color Blob Tracking Example
      #
      # This example shows off multi color blob tracking using the OpenMV Cam.
      
      import sensor, image, time, math
      
      red = (22, 67, 19, 84, -12, 53)# generic_red_thresholds
      black= (0, 31, -34, 41, 24, -21)# generic_black_thresholds
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      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. Don't set "merge=True" becuase that will merge blobs which we don't want here.
      
      def find_max(blobs):    #寻找最大色块函数定义
           max_pixels=0         #通过像素比较
           for blob in blobs:     #blob[0,1,2,3,4]=x,y,w,h,pixels (int)
               if blob[4]>max_pixels:
                   max_blob=blob
                   max_pixels=blob[4]
           return max_blob
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          red_blobs= img.find_blobs([red])
          black_blobs= img.find_blobs([black])
      
      if red_blobs:
             max_blob_red=find_max(red_blobs)
             img.draw_rectangle(max_blob_red.rect())
             img.draw_cross(max_blob_red.cx(),max_blob_red.cy())
             red_x_error = int(max_blob_red.cx()-img.width()/2)
             red_y_error = int(max_blob_red.cy()-img.height()/2)
      if black_blobs:
             max_blob_black=find_max(black_blobs)
             img.draw_rectangle(max_blob_black.rect())
             img.draw_cross(max_blob_black.cx(),max_blob_black.cy())
             black_x_error = int(max_blob_black.cx()-img.width()/2)
             black_y_error = int(max_blob_black.cy()-img.height()/2)
      #print(blob.code())
      print(clock.fps())
      
      


    • 缩进不对,导致逻辑不对。