星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的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 ,pyb
      from pyb import UART
      from pyb import Pin
      import json
      uart = UART(3, 19200)
      led1 = pyb.LED(1)
      led2 = pyb.LED(2)
      led3 = pyb.LED(3)
      # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
      # The below thresholds track in general red/green things. You may wish to tune them...
      thresholds = [(42,100, 29, 65, 12, 50), # generic_red_thresholds28, 89, -52, -2, -8, 50
                    (42, 65, -47, -11, 10, 41), # generic_green_thresholds 31, 86, -3, 20, -49, 14
                    (19, 53, -1, 27, -50, 0)] # generic_blue_thresholds 30, 66, 44, 80, 26, 69
      # You may pass up to 16 thresholds above. However, it's not really possible to segment any
      # scene with 16 thresholds before color thresholds start to overlap heavily.
      
      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
      ROI=(0,20,100,200)
      clock = time.clock()
      p_out = Pin('P7', Pin.OUT_PP)#设置p_out为输出引脚
      p_out.high()#设置p_out引脚为高
      p_out.high()#设置p_out引脚为高
      # 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.
      a=0
      b=1
      c=2
      d=4
      n=0
      classmates = []
      while(True):
          clock.tick()
          #led1.on()
          #led2.on()
          #led3.on()
          img = sensor.snapshot()
          for blob in img.find_blobs(thresholds,roi=ROI,pixels_threshold=200, area_threshold=200):
              # These values depend on the blob not being circular - otherwise they will be shaky.
              statistics = img.get_statistics(roi=ROI)
              if a<1:
                  if 42<statistics.l_mode()<100 and 29<statistics.a_mode()<65 and 12<statistics.b_mode()<50:#if the circle is red
                      img.draw_rectangle(blob.rect(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来
                 #55, 40, 29, 65, 12, 50
                  #a=a+1
                  #print(1)   45, 72, 19, 71, -14, 44
                      a+=1
                  #a=a+1
                      print ('a=',a)
                      classmates.append(a)
              if b<2:
                  if 42<statistics.l_mode()<65 and -47<statistics.a_mode()<-11 and 10<statistics.b_mode()<41:#if the circle is red
                      img.draw_rectangle(blob.rect(), color = (0, 255,0))#识别到的红色圆形用红色的圆框出来
                  #40, 66, -22, -2, -6, 27
                      b+=1
                      print ('b=',b)
                      classmates.append(b)
              if c<3:
                  if 19<statistics.l_mode()<53 and -1<statistics.a_mode()<27 and -50<statistics.b_mode()<0:#if the circle is red
                      img.draw_rectangle(blob.rect(), color = (0, 0, 255))#识别到的红色圆形用红色的圆框出来
                  #19, 36, -3, 18, -23, -4
                      c+=1
                      print ('c=',c)
                      classmates.append(c)
              if n<a<b<c:
                  print (classmates)
                  output_str = json.dumps(classmates)
                  uart.write(output_str)
                  m=len(classmates)
                  if m>2:
                      n=1
      ![0_1558949881923_11.png](https://fcdn.singtown.com/b6bfc985-6722-47f5-835e-db20b46eb94d.png) 
      


    • 0_1558949939430_11.png



    • 不要把很多功能放在一起。

      我的建议:
      先只调用img.find_blobs,print看看得到的是什么。

      然后print看看statistics的值是什么。