• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 请问在色块识别程序中,锚定框将非选定颜色的物品框住后,添加什么程序可以让锚定框与锚定框间不重合?



    • import sensor
      import image
      import time
      import math
      import lcd
      
      threshold_index = 0
      
      thresholds = [(72, 40, -29, 60, -62, -2)]
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time=2000)
      sensor.set_auto_gain(False) # 关闭增益
      sensor.set_auto_whitebal(False) # 关闭白平衡
      clock = time.clock()
      lcd.init()
      
      roi = (0, 0, 320, 240)
      
      blue_threshold = (72, 40, -29, 60, -62, -2)
      
      detected_rectangles = []  # 添加一个保存矩形的列表
      
      # 定义矩形重叠函数
      def rectangle_overlap(rect1, rect2):
          x_overlap = max(0, min(rect1[0] + rect1[2], rect2[0] + rect2[2]) - max(rect1[0], rect2[0]))
          y_overlap = max(0, min(rect1[1] + rect1[3], rect2[1] + rect2[3]) - max(rect1[1], rect2[1]))
          overlap_area = x_overlap * y_overlap
          rect1_area = rect1[2] * rect1[3]
          rect2_area = rect2[2] * rect2[3]
          return overlap_area > 0 and overlap_area / min(rect1_area, rect2_area) > 0.5
      
      while True:
          clock.tick()
          img = sensor.snapshot()
          time.sleep(2)
          img = img.crop(roi)
          blobs = img.find_blobs([blue_threshold])
          for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=50, area_threshold=50, invert=True, merge=False):
              if blob.elongation() > 0.5:
                  img.draw_edges(blob.min_corners(), color=(255, 0, 0))
                  img.draw_line(blob.major_axis_line(), color=(0, 255, 0))
                  img.draw_line(blob.minor_axis_line(), color=(0, 0, 255))
              img.draw_rectangle(blob.rect())
              current_rectangle = blob.rect()  # 记录当前矩形
              is_overlap = False
              for rectangle in detected_rectangles:
                  if rectangle_overlap(current_rectangle, rectangle):
                      is_overlap = True
                      break
              if not is_overlap:
                  detected_rectangles.append(current_rectangle)  # 将矩形添加到列表中
              img.draw_cross(blob.cx(), blob.cy())
              img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20)
          print("target count:", len(detected_rectangles))  # 统计矩形个数
          print(clock.fps())
      
          lcd.display(img)
      


    • 我没听懂,”锚定框与锚定框间不重合“是什么意思?