• 星瞳AI VISION软件内测!可以离线标注,训练,并生成OpenMV的模型。可以替代edge impulse https://forum.singtown.com/topic/8206
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 现在就是串口调试工具发送1运行1的部分,发送2没有变化怎么修改小白求助



    • # Untitled - By: 15622 - 周四 10月 6 2022
      # Single Color RGB565 Blob Tracking Example
      # This example shows off single color RGB565 tracking using the OpenMV Cam.
      import sensor, image, time, math
      import sensor, image, time
      from pyb import UART                #加入
      import json                    #载入库  加入
      import pyb
      import math
      def modified_data(data):
         data = int(data)
         str_data = ''
         if data < 10:
             str_data = str_data + '000' + str(data)
         elif data >= 10 and data < 100:
             str_data = str_data + '00' + str(data)
         elif data >=100 and data <1000:
             str_data = str_data + '0' + str(data)
         else:
             str_data = str_data + str(data)
         return str_data.encode('utf-8')
      kernel_size = 1 # kernel width= (size*2)+1, kernel height = (size*2)+1,默认不需改
      kernel = [-2, -1,  0, \
                -1,  1,  1, \
                 0,  1,  2]
      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 = [(100, 8, -13, -57, 25, 127), # generic_red_thresholds
                    ] # generic_blue_thresholds
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(time = 300)
      uart = UART(3, 115200)
      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()
      sj=0
      while(True):
          clock.tick()
          if uart.any():
              sj = uart.read(1)
              sj=int(sj)
      # 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.
      
              while(sj==1):
                  img = sensor.snapshot().lens_corr(1.8 )       #镜头畸变矫正
                  img.morph(kernel_size, kernel)        #核滤波
                  img.laplacian(1, sharpen=True)        #锐化
                  for c in img.find_circles(threshold = 6001, x_margin = 10, y_margin = 10, r_margin = 10,
                  r_min = 15, r_max = 100, r_step = 2):
                #只需修改threshold和r_min,增大threshold可以提高准确性,减小可以提高灵敏度(太小会乱框)
                 # 修改r_min值使其只识别大圆,不识别小圆
                #if c.r()>15 and c.r()<80:
                      area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
                    #area为识别到的圆的区域,即圆的外接矩形框
                      img.draw_rectangle(area, color = (255,255,255)) #将圆用白色的矩形框出来
                      img.draw_cross(c.x(),c.y())      #画十字
                      mj=4*c.r()*c.r()        #矩形框面积
                      xzb = modified_data(c.x())
                      yzb = modified_data(c.y())
                      mjzb = modified_data(mj)
                      uart.write('st')
                      uart.write(xzb)
                      uart.write(yzb)
                      uart.write(mjzb)                    # 串口发送数据
                      print(xzb, yzb,mjzb)
      
              while(sj==2):
                  img = sensor.snapshot()
                  for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=500, area_threshold=400, merge=True):
              # These values depend on the blob not being circular - otherwise they will be shaky.
                      if blob.elongation()>0.5:
                          img.draw_edges(blob.min_corners(), color=(255,0,0))
                          img.draw_cross(blob.cx(), blob.cy())
              # Note - the blob rotation is unique to 0-180 only.
                      img.draw_rectangle(blob.rect())
                      img.draw_cross(blob.cx(), blob.cy())
                      mj=blob.w()*blob.h()
                      xzb = modified_data(blob.cx())
                      yzb = modified_data(blob.cy())
                      mjzb = modified_data(mj)
                      uart.write('st')
                      uart.write(xzb)
                      uart.write(yzb)
                      uart.write(mjzb)
                      print(xzb, yzb,mjzb)
      


    • 50行和73行的while改成if