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



    • # Untitled - By: ASUS - 周二 9月 6 2022
      
      import sensor, image, time, pyb, math
      import json, ustruct
      from pyb import UART ,LED
      
      #*********************************************************************
      def find_max(blobs):
          max_size=0
          global max_blob
      
          for blob in blobs:
              if blob[2]*blob[3] > max_size and 50<blob.cy()<150:
                  max_blob=blob
                  max_size = blob[2]*blob[3]
          return max_blob
      #*********************************
      def detect(max_blob):
          global mark
          #judge=0
          #nothing=0
          row_data=[-1,-1]
          print(max_blob.density())
          #mark=([-1,-1],[-1,-1]) #1 yellow 2 green 3 blue 4 red ;1 rect 2 circle 3 rt
          #shape=0 #1是圆 2是矩形 圆形和矩形直接用函数识别,剩下的判断是不是三角形 3是三角形
          #colour=0
      
          if  max_blob.density()>0.82:
              row_data[0]=max_blob.code()
              img.draw_rectangle(max_blob.rect())
              row_data[1]=1
      
          elif max_blob.density()>0.6:
              img.draw_circle((max_blob.cx(), max_blob.cy(),int((max_blob.w()+max_blob.h())/4)))
              row_data[0]=max_blob.code()
              row_data[1]=2
          elif max_blob.density()>0.4:
                  img.draw_cross(max_blob.cx(), max_blob.cy())
                  row_data[0]=max_blob.code()
                  row_data[1]=3
          return row_data
      #*********************************
      def sending_data(a,b):
          global uart;
          #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
          #data = bytearray(frame)
          data_end = ustruct.pack("<bbhhb",      #格式为俩个字符俩个短整型(2字节)
                         0x2C,                      #帧头1
                         0x12,                      #帧头2
                         int(a), # up sample by 4   #数据1
                         int(b), # up sample by 4    #数据2
                         0x5B)
          uart.write(data_end);   #必须要传入一个字节数组
      #********************************************************************
      red=(8, 55, 73, 10, -71, 57)
      green=(63, 22, -83, -4, 50, -23)
      blue=(52, 7, 40, -73, -15, -117)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      
      uart = UART(3, 115200)
      uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
      
      clock = time.clock()
      #********************************************************************
      while(True):
          clock.tick()
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)#畸变矫正
          blobs = img.find_blobs([red,green,blue],area_threshold=100
          )
          data=detect(find_max(blobs))
          print(data)
          sending_data(data[0],data[1])
          #uart.write(jsonstr)
          #break
          #print(clock.fps())
      
      


    • 方形如果旋转了,那么最外框就变了,所以density就变了。

      这种情况,用roundness分析一下

      https://docs.singtown.com/micropython/zh/latest/openmvcam/library/omv.image.html#blob.roundness