导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. gk2p
    G
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    gk2p

    @gk2p

    0
    声望
    2
    楼层
    546
    资料浏览
    0
    粉丝
    0
    关注
    注册时间 最后登录

    gk2p 关注

    gk2p 发布的帖子

    • RE: VGA格式,使用img = sensor.snapshot().copy(),报错内存

      板子信息为:板子:OpenMV Cam H7(STM32H743)
      传感器:OV7725固件版本:4.5.4-[最新]

      发布在 OpenMV Cam
      G
      gk2p
    • VGA格式,使用img = sensor.snapshot().copy(),报错内存
      import sensor, image, time, json, utime
      from machine import UART
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)  # 灰度更快
      sensor.set_framesize(sensor.VGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      
      
      # 颜色阈值
      red_threshold = (76, 53, 58, 15, -21, 52) # 红色激光点
      
      uart = UART(3, 115200)  # 初始化串口
      
      # 初始化列表
      coordinates_red = [("", "")] * 1  # 初始化红色激光点列表,假设存储1个点
      enum_data = [("", "")] * 4  # 存储矩形角点,假设存储4个角点
      
      # 寻找像素最多的红色色块
      def find_largest_red_blob(img):
          largest_blob = None
          max_pixels = 0
          for blob in img.find_blobs([red_threshold], pixels_threshold=10, area_threshold=20, merge=True):
              if blob.pixels() > max_pixels:
                  largest_blob = blob
                  max_pixels = blob.pixels()
          return largest_blob
      
      
      while True:
          clock.tick()
          img = sensor.snapshot().copy()
         # enum_data.clear()  # 每次循环开始时清空矩形数据列表
         # coordinates_red.clear()  # 清空红色激光点列表
      
      
          largest_blob = find_largest_red_blob(img)
          if largest_blob:
              cx = largest_blob.cx()
              cy = largest_blob.cy()
              img.draw_circle(cx, cy, 2, color=(0, 255, 255), thickness=2)
              cx_str = "{:03d}".format(cx)  # 将坐标格式化为3位数的字符串
              cy_str = "{:03d}".format(cy)  # 将坐标格式化为3位数的字符串
              coordinates_red[0] = (cx_str, cy_str)
              #print("Blob at ({}, {})".format(cx, cy))
      
          r = img.find_rects(threshold=26000)  # 找到矩形
          if r:
              r = r[0]  # 仅处理第一个矩形
              for i, p in enumerate(r.corners()):
                  img.draw_circle(p[0], p[1], 2, color = (0, 255, 0))
                  px = "{:03d}".format(p[0])  # 将横坐标转换为3位数的字符串
                  py = "{:03d}".format(p[1])  # 将纵坐标转换为3位数的字符串
                  enum_data[i] = (px, py)
              #print("rect:({})".format(enum_data))
      
          del img
      
          # 发送所有收集的数据
      #    if coordinates_red:
      #        uart.write("R" + str(coordinates_red) +"250"+"E" + "\r\n")
      #        #coordinates_red.clear()  # 清空红色激光点列表
      
          uart.write("T"+str(enum_data)+str(coordinates_red)+"E"+"E"+"E"+"\r\n")
          print(str(enum_data))
          print(str(coordinates_red))
          print("FPS %f" % clock.fps())
          print("\r\n")
      
          utime.sleep_ms(10)  # 延迟100毫秒
      
      
      请在这里粘贴代码
      

      0_1715316238367_屏幕截图 2024-05-10 123812.png

      发布在 OpenMV Cam
      G
      gk2p