• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 打印出来的(x,y,w,h)中的w,h的被测物体宽度和高度像素点的大小吗?是的话怎样转换成实际物体大小?



    • 寻找最大的矩形

      沿矩形边框绘制线条

      import sensor, image, time

      相机初始化

      sensor.reset()
      sensor.set_pixformat(sensor.GRAYSCALE) # 设置图像格式为灰度
      sensor.set_framesize(sensor.QQQVGA) # 设置图像大小
      sensor.skip_frames(time=2000) # 等待设置生效
      clock = time.clock() # 用于跟踪帧率

      while(True):
      clock.tick()
      img = sensor.snapshot().lens_corr(1.8)

      # 使用find_rects()方法寻找图像中的矩形
      rects = img.find_rects(threshold = 10000)
      
      # 初始化变量来存储最大矩形的信息
      max_area = 0
      max_rect = None
      
      # 遍历所有找到的矩形,找出面积最大的矩形
      for rect in rects:
          # 计算当前矩形的面积
          area = rect.w() * rect.h()
          # 如果当前矩形的面积大于之前记录的最大面积,则更新最大矩形和最大面积
          if area > max_area:
              max_area = area
              max_rect = rect
      
      # 如果找到了最大的矩形,则绘制它的边框
      if max_rect:
          corners = max_rect.corners()    # 获取最大矩形的四个角点
          # 绘制最大矩形的四条边
          for i in range(len(corners)):
              start_point = corners[i]
              end_point = corners[(i+1) % 4]
              img.draw_line(start_point[0], start_point[1], end_point[0], end_point[1], color = 255)
      
          print(corners)




    • 使用这个例程之后,移动物体与摄像头之间的距离,串口返回的数值不变的,这是为什么?

      # Measure the distance
      #
      # This example shows off how to measure the distance through the size in imgage
      # This example in particular looks for yellow pingpong ball.
      
      import sensor, image, time
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      yellow_threshold   = (33, 96, -34, 42, -13, 28)
      # You may need to tweak the above settings for tracking green things...
      # Select an area in the Framebuffer to copy the color settings.
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.
      
      K=3920 #the value should be measured
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
      
          blobs = img.find_blobs([yellow_threshold])
          if len(blobs) == 1:
              # Draw a rect around the blob.
              b = blobs[0]
              img.draw_rectangle(b[0:4]) # rect
              img.draw_cross(b[5], b[6]) # cx, cy
              Lm = (b[2]+b[3])/2
              length = K/Lm
              print(length)
              #print(Lm)
      
          #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
          # connected to your computer. The FPS should increase once disconnected.请在这里粘贴代码
      


    • 而且使用上面的例程,摄像头捕捉到的是整个显示框,不是物体大小的size0_1714267966017_微信图片_20240428093231.png