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



    • 0_1605148033764_6918f042-f42f-49c7-ac62-194454f772b9-image.png



    • # Untitled - By: 86183 - 周五 9月 11 2020
      
      import sensor, image, time, math
      from pyb import UART
      
      threshold_index = 0
      #thresholds = thresholds = [(11, 15, 19, 35, -27, 35), #red
      #                           (7, 17, -73, 14, -46, -16), #blue
      #                           (11, 68, -87, -22, -27, 58)] #green
      thresholds = [(29, 88, 94, 36, 86, -54),
                   (7, 63, -3, 77, -31, -69),
                   (38, 81, -128, -35, -128, 127) ]
      
      sensor.reset()
      sensor.set_vflip(True)      #图像垂直翻转
       #截取图像
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_windowing((0,83,320,97))
      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()
      
      DetectFlag = False
      
      def draw_keypoints(img, kpts):
          if kpts:
              print(kpts)
              img.draw_keypoints(kpts)
              img = sensor.snapshot()
              time.sleep(1000)
      #初始化串口
      uart = UART(1, 9600)
      uart.init(9600, bits=8, parity=None, stop=1)
      
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob.pixels() > max_size:
                  max_blob=blob
                  max_size = blob.pixels()
          return max_blob
      
      #初始化变量
      x = 0
      green_position = 0
      send_1 = 0  #颜色识别模块发送的内容
      x_red = 0
      x_blue = 0
      x_green = 0
      Num_Blob = 0
      while(True):
              clock.tick()
              img = sensor.snapshot()
      
              blobs = img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200)        
              if blobs:
                   max_blob = find_max(blobs)
                   img.draw_rectangle(max_blob.rect()) # rect
                   img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy
                     
      
              for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200):
                  x_red = blob.cx()
                  img.draw_rectangle(blob.rect())
              for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200):
                  x_blue = blob.cx()
                  img.draw_rectangle(blob.rect())
              for blob in img.find_blobs([thresholds[2]], pixels_threshold=200, area_threshold=200):
                  x_green = blob.cx()
                  img.draw_rectangle(blob.rect())
      
              if(x_red < x_green and x_green < x_blue):
                  #send_1 = 'RGB'
                  send_1 = '321'
              elif(x_red < x_blue and x_blue < x_green):
                  #send_1 = 'RBG'
                  send_1 = '231'
              elif(x_green < x_red and x_red < x_blue):
                  #send_1 = 'GRB'
                  send_1 = '312'
              elif(x_green < x_blue and x_blue < x_red):
                  #send_1 = 'GBR'
                  send_1 = '132'
              elif(x_blue < x_red and x_red < x_green):
                  #send_1 = 'BRG'
                  send_1 = '213'
              elif(x_blue < x_green and x_green < x_red):
                  #send_1 = 'BGR'
                  send_1 = '123'
              #发串口
              print('%s' %(send_1))
              uart.write('%s' %(send_1))
              uart.write('\r\n')
              #img.draw_rectangle((0,75,321,103))