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



    • 
      import sensor, image, time
      from pyb import UART
      from pyb import Servo
      import cpufreq
      import pyb
      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 = [(58, 88, 57, -4, 20, 70)] # generic_red_thresholds
                                                  # generic_green_thresholds
                                                  # generic_blue_thresholds
      threshold2 = [(30, 47, -39, 19, 20, 42)]
      avg=[0,0,0,0,0,0,0,0,0,0,0,0]
      sort2_servo=Servo(1)
      led = pyb.LED(3)
      #cpufreq.set_frequency(cpufreq.CPUFREQ_216MHZ)
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      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()
      
      # 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. "merge=True" merges all overlapping blobs in the image.
      
      uart=UART(3,115200)
      
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob[2]*blob[3] > max_size:
                  max_blob=blob
                  max_size = blob[2]*blob[3]
          return max_blob
      
      ROI=(0,0,1,1)
      
      while(True):
          data = 0
          clock.tick()
          img = sensor.snapshot()
          sort2_servo.angle(-900)
          time.sleep(20)
          #time.sleep(10)
          blobs = img.find_blobs([thresholds[0]], pixels_threshold=80, area_threshold=850, merge=True)
          if blobs:
                    max_blob = find_max(blobs)
                    ROI = max_blob.rect()
                    xc = max_blob.cx()
                    yc = max_blob.cy()
                    x = max_blob.x()
                    y = max_blob.y()
                    xn = int(xc-(xc-x)*7/10)
                    yn = int(yc-(yc-y)*7/10)
                    wn = (xc-xn)*2
                    hn = (yc-yn)*2
                    ROI = (xn, yn, wn, hn)
                    img.binary(thresholds)
                    #Bimg.erode(2)
                    #img.dilate(1)
                    statistics=img.get_statistics(roi=ROI)
                    avg = statistics.mean()
                    print(avg)
                    if(uart.any()):
                         data = uart.readline()
                         
                    if ( data!=0):#avg>=50 and avg<=95 or
                        print("bad")
                        print(data)
                        print(uart.any())
                        #led.on()
                        #time.sleep(150)
                        #ed.off()
                        sort2_servo.angle(0)       #添加时期2018.4.20
                        time.sleep(1000)        #添加时期2018.4.20
                        sort2_servo.angle(-900)           #添加时期2018.4.20
                        time.sleep(1000)        #添加时期2018.4.20
                        data = 0
                    elif (avg>95):
                        sort2_servo.angle(-900)           #添加时期2018.4.20
                        time.sleep(100)
                        print("good")
                        print(uart.any())
          #print(clock.fps())
          #print(cpufreq.get_frequency())
      
      


    • 直接uart.read(timeout_char=0)应该可以立即把数据读出来,就清空了缓冲区。



    • @kidswong999两个MV之间通信怎么清空接收方UART.ANY()里的数据从而重新查询。 中说:

      uart.read(timeout_char=0)

      0_1525671065372_5.7.jpg
      但是报错了大佬。