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



    • # Single Color RGB565 Blob Tracking Example
      #
      # This example shows off single color RGB565 tracking using the OpenMV Cam.
      
      import sensor,image,math,time
      import sending
      threshold_index = 0 # 0 for red, 1 for green, 2 for blue
      
      # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
      # The below thresholds track in general red/green/blue things. You may wish to tune them...
      thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds     #只有红色
                    (30, 100, -64, -8, -32, 32), # generic_green_thresholds   #只有绿色
                    (0, 30, 0, 64, -128, 0)] # generic_blue_thresholds        #只有蓝色
      ![0_1550589074881_H__Measure.py - OpenMV IDE 2019_2_19 23_07_37.png](https://fcdn.singtown.com/9dccc9e7-b392-4679-b7be-3c8a829ac677.png) 
      
      #while (True):
      #    View_Color()
      
      
      # Measure the distance
      #
      # This example shows off how to measure the distance through the size in imgage
      # This example in particular looks for yellow pingpong ball.
      
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      
      #yellow_threshold   = ( 56,   83,    5,   57,   63,   80)
      
      # You may need to tweak the above settings for tracking green things...
      # Select an area in the Framebuffer to copy the color settings.
      
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.
      
      i = sending.receive_data()
      K=5000 #the value should be measured  需根据要识别物体来确定初始化比例大小
      #实际大小=K*宽的像素
      
      # Single Color RGB565 Blob Tracking Example
      #
      # This example shows off single color RGB565 tracking using the OpenMV Cam.
      
      #分别给i赋值1,2,3
      j = 1
      def R_G_B(j):   #寻找最大色块的坐标
          if j <= 3:
              max_size=0
              clock.tick()
              img = sensor.snapshot()
              for blob in img.find_blobs([thresholds[j-1]]):
                      #色块中心的坐标
                  if blob.pixels() > max_size:
                      max_blob = blob
                      max_size = blob.pixels()
                      img.draw_rectangle(blob.rect())
                      img.draw_cross(blob.cx(), blob.cy())
                      return max_blob
                      #print('sum :', len(blob))
                  else:
                      return 0
              print(clock.fps())
      
      
      def R_G_B_center(k):
          m = R_G_B(j)
          x = blob.cx()
          y = blob.cy()
          return x,y
      #while True:
      #    R_G_B(1)
      
      
      def measure_distance(i):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          blobs = R_G_B(i)
          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
              if abs(b[2]-b[3])>2:    #判断是否为球、正方体或其他立方体
                  Lm = b[3]
              else:
                  Lm = (b[2]+b[3])/2
              length = K/Lm               #距离 = k/直径的像素
          return length
              #print(b[2])
      
      #while True:
      #    Measure_Distance()
          #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
          # connected to your computer. The FPS should increase once disconnected.
      
      
      

      0_1550589080611_H__Measure.py - OpenMV IDE 2019_2_19 23_07_30.png 0_1550589088949_H__Measure.py - OpenMV IDE 2019_2_19 23_07_37.png



    • 因为blob类型没有len,怎么了?



    • @kidswong999 那为什么测距例程里面就有这种len()用法,而且编译例程没错。到我这里编译main函数就说错了?

      import sensor, image, time

      Measure the distance

      This example shows off how to measure the distance through the size in imgage

      This example in particular looks for yellow pingpong ball.

      import sensor, image, time

      For color tracking to work really well you should ideally be in a very, very,

      very, controlled enviroment where the lighting is constant...

      yellow_threshold = ( 56, 83, 5, 57, 63, 80)

      You may need to tweak the above settings for tracking green things...

      Select an area in the Framebuffer to copy the color settings.

      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.

      K=5000#the value should be measured

      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([yellow_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)
      
      #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
      # connected to your computer. The FPS should increase once disconnected.
      

      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)

      clock = time.clock()

      while(True):
      clock.tick()
      img = sensor.snapshot()
      print(clock.fps())



    • 因为你的R_G_B函数返回的是一个blob,而不是很多个blob。



    • @kidswong999 那怎样让他返回很多个blob?



    • 你写的函数我又不知道用处是什么。又不可能给你改。