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



    • # Template Matching Example - Normalized Cross Correlation (NCC)
      #
      # 这个例子展示了如何使用OpenMV凸轮的NCC功能将小部分图像与图像的各个部分
      # 进行匹配...期望获得极其可控的环境NCC并不是全部有用的。
      #
      # 警告:NCC支持需要重做!到目前为止,这个功能需要做大量的工作才能有用。
      # 这个脚本将重新表明功能的存在,但在目前的状态是不足的。
      
      import time, sensor, image
      from image import SEARCH_EX, SEARCH_DS
      from pyb import UART
      thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds -> index is 0 so code == (1 << 0)
                    (30, 100, -64, -8, -32, 32), # generic_green_thresholds -> index is 1 so code == (1 << 1)
                    (0, 15, 0, 40, -80, -20)] # generic_blue_thresholds -> index is 2 so code == (1 << 2)
      sensor.reset()
      sensor.set_contrast(1)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_pixformat(sensor.GRAYSCALE)
      templates1 = ["0.pgm"] #保存多个模板
      templates2 = ["1.pgm"] #加载模板图片
      uart = UART(3, 115200)
      uart.init(115200, bits=8, parity=None, stop=1) # 8位数据位,无检验位,1位停止位
      tmp = 0
      clock = time.clock()
      while (True):
          clock.tick()
          img = sensor.snapshot()
          for t in templates1:
              template = image.Image(t)
              r = img.find_template(template, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
              if r:
                  img.draw_rectangle(r)
                  img.draw_string(10,10, "zhituan")
                  tmp = uart.write('d')
                  print(tmp,t)
                  if t:
                      img = img.to_rgb656()
                      for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
                             img.draw_rectangle(blob.rect())
                             img.draw_cross(blob.cx(), blob.cy())
                             print(blob.code())
                      
      
          for t in templates2:
              template = image.Image(t)
              r = img.find_template(template, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
              if r:
                  img.draw_rectangle(r)
                  img.draw_string(10,10, "dianchi")
                  tmp = uart.write('0')
                  print(tmp,t)
                  if t:
                      img = img.to_rgb656()
                      for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
                             img.draw_rectangle(blob.rect())
                             img.draw_cross(blob.cx(), blob.cy())
                             print(blob.code())
      
          #print(clock.fps())