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



    • 如图所示在串行终端显示“Learning thresholds”的时候摄像头还能对物体进行追踪,但在“Threshold learned...”和“Tracking colors...”出现之后就追踪不到,请问哪里还需要修改。

      import sensor, image,time,pyb
      from pyb import UART
      
      uart = UART(3,9600)
      
      print("Letting auto algorithms run. Don't put anything in front of the camera!")
      
      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()
      
      K=650#the value should be measured  50*13
      K2=0.1#实际大小=k*直径的像素  k=5/50
      
      # Capture the color thresholds for whatever was in the center of the image.
      r = [(320//2)-(50//2), (240//2)-(50//2), 50, 50] # 50x50 center of QVGA.
      
      print("Auto algorithms done. Hold the object you want to track in front of the camera in the box.")
      print("MAKE SURE THE COLOR OF THE OBJECT YOU WANT TO TRACK IS FULLY ENCLOSED BY THE BOX!")
      for i in range(60):
          img = sensor.snapshot()
          img.draw_rectangle(r)
      
      print("Learning thresholds...")
      threshold = [50, 50, 0, 0, 0, 0] # Middle L, A, B values.
      for i in range(60):
          r = [(320//2)-(50//2), (240//2)-(50//2), 50, 50] # 50x50 center of QVGA.
          img = sensor.snapshot()
          hist = img.get_histogram(roi=r)
          lo = hist.get_percentile(0.01) # Get the CDF of the histogram at the 1% range (ADJUST AS NECESSARY)!
          hi = hist.get_percentile(0.99) # Get the CDF of the histogram at the 99% range (ADJUST AS NECESSARY)!
          # Average in percentile values.
          threshold[0] = (threshold[0] + lo.l_value()) // 2
          threshold[1] = (threshold[1] + hi.l_value()) // 2
          threshold[2] = (threshold[2] + lo.a_value()) // 2
          threshold[3] = (threshold[3] + hi.a_value()) // 2
          threshold[4] = (threshold[4] + lo.b_value()) // 2
          threshold[5] = (threshold[5] + hi.b_value()) // 2
          for blob in img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
              img.draw_rectangle(blob.rect())
              img.draw_cross(blob.cx(), blob.cy())
              img.draw_rectangle(r)
      
      print("Thresholds learned...")
      print("Tracking colors...")
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          for blob in img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
              blobs = img.find_blobs([threshold])
              if len(blobs) == 1:
                  # Draw a rect around the blob.
                  b = blobs[0]
                  img.draw_rectangle(b[0:4]) # rect
                  img.draw_cross(b[5], b[6]) # cx, cy
                  Lm = (b[2]+b[3])/2
                  length = K/Lm
                  print("length:%s cm"%(length))
                  #print(Lm)
                  size=K2*Lm
                  print(size)
      
                  h=K2*b[3]
                  w=K2*b[2]
                  print("high:%s cm, width:%s cm"%(h,w))
      
                  output_str="[%.1f,%.1f,%.1f]" % (length,h,w)
                  print('you send:',output_str)
                  uart.write(output_str+'\r\n')
              else:
                  print('not found!')
      
      
      
      
          #print(clock.fps())
      

      0_1556306538233_1.png 0_1556306543372_2.png 0_1556306547694_3.png



    • 你的代码是错的。

      for blob in img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10):
              blobs = img.find_blobs([threshold])
              if len(blobs) == 1:
      

      为什么for循环里面还要再找色块?



    • @kidswong999 因为要测距啊,那要怎么改



    • 你的代码是错的。只需要调用一次find_blobs

      blobs = img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10)
      for blob in blobs:
          xxxx