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



    • import sensor, image, time,pyb,math, struct
      from pyb import LED,Timer
      from pyb import UART
      uart = UART(3,500000)#初始化串口 波特率 500000
      
      BlackPole=(0, 17, -26, 39, -11, 40)
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.set_windowing((70,0,40,120))
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.
      led = pyb.LED(3) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.
      class Dot(object):
          flag = 0   #杆检测标志 1代表红色  2代表绿色
          black_cnt = 0
      
      Dot=Dot()
      class Receive(object):
          uart_buf = []
          mode = 0
      
      R=Receive()
      #读取串口缓存
      def UartReadBuffer():
          i = 0
          Buffer_size = uart.any()
          while i<Buffer_size:
              R.uart_buf.append(uart.readchar())
              print("found: Modeflag=",R.uart_buf[0]) #从单片机发给openmv的数据是50
              if (R.uart_buf[0]==32):
                 R.mode=1
              if (R.uart_buf[0]==30):
                 Dot.black_cnt=1
              i = i + 1
      #串口发送函数
      def UartSendData(Data):
          uart.write(Data)
      #杆检测数据打包
      def DotDataPack(flag):
          #print("found: flag=",flag)
          pack_data=bytearray([flag])
          return pack_data
      
      #色块识别函数
      #定义函数:找到画面中最大的指定色块
      def FindMax(blobs):
          max_size=1
          if blobs:
              max_blob = 0
              for blob in blobs:
                  blob_size = blob.w()*blob.h()
                  if ( (blob_size > max_size) & (blob_size > 100)   ) :#& (blob.density()<1.2*math.pi/4) & (blob.density()>0.8*math.pi/4)
                      if ( math.fabs( blob.w() / blob.h() - 1 ) < 2.0 ) :
                          max_blob=blob
                          max_size = blob.w()*blob.h()
              return max_blob
      
      def LineFilter(src, dst):
        for i in range(0, len(dst), 1):
            dst[i] = src[i<<1]
      while(True):
          UartReadBuffer()
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot(line_filter = LineFilter)#拍一张图像
          Black_blobs = img.find_blobs([BlackPole], pixels_threshold=3, area_threshold=3, merge=True, margin=5)#识别红色物体
          max_blob = FindMax(Black_blobs)#找到最大的黑色色块那个
          if (max_blob) and (R.mode==1):
              img.draw_cross(max_blob.cx(), max_blob.cy())#物体中心画十字
              img.draw_rectangle(max_blob.rect())#画圈
              LED(3).toggle()
              if(Dot.black_cnt==0):#第一次黑色色块识别
                 Dot.flag =33
              if(Dot.black_cnt==1):#第二次黑色色块识别
                 Dot.flag =34
          #print(Dot.flag)
          UartSendData(DotDataPack(Dot.flag))
      
      
      
      
      


    • 从单片机发给openmv的数据是50
      报错:MemoryError: memory allocation failed, allocating 131072 bytes



    • 你用的是什么硬件?



    • @kidswong999 smt32f407



    • @ghbd 使用OpenMV4 H7



    • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。