【问题标题】:Rectangles overlapping矩形重叠
【发布时间】:2018-11-02 04:49:45
【问题描述】:

我正在使用 opencv 在图像上绘制矩形,其中包含列表中给出的矩形的 xmin、ymin、xmax、ymax 值。

点列表是

点 = [(1707.0, 1865.0, 2331.0, 2549.0),(1348.0, 1004.0, 1987.0, 1746.0),(749.0, 2129.0, 1674.0, 2939.0) ,(25.0, 1134.0, 1266.0, 2108.0),(253.0, 1731.0, 1403.0, 2449.0)]

image = cv2.imread("pathtoimage")
for point in points:
    xmin,ymin,xmax,ymax = point
    result_image = cv2.rectangle(image, (int(xmin), int(xmax)), (int(ymin),int(ymax)), (0,255,0), 8)
    os.remove("/home/atul/Documents/CarLabel/imagemapping1-wp-BD489663-BD55-484E-9EA7-EB5662B626B9.png")
    cv2.imwrite("/home/atul/Documents/CarLabel/imagemapping1-wp-BD489663-BD55-484E-9EA7-EB5662B626B9.png",result_image)

矩形相互重叠。 我该如何解决这个问题。

原图

生成的图像

【问题讨论】:

  • 数据点重叠。您希望最终结果如何?
  • 最终的结果应该像矩形一样,根据点数据得到坐标而不相互重叠。
  • 您是否使用boundingRect() 生成点,因为您需要使用minAreaRect()如果您想考虑旋转框...参见7b...docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html
  • @MarkSetchell 在用户在对象上绘制矩形后没有生成任何点,我们得到每 4 个点的 x、y 坐标,然后从这些 xy 坐标值中找到 xmin、ymin、xmax、ymax。
  • 你怎么知道你对xmin,xmax,ymin,ymax的计算是正确的?您是否手动绘制了几个矩形来检查重叠?

标签: python opencv image-processing


【解决方案1】:

cv2.rectangle 需要 top-leftbottom-right 点的坐标。所以你应该使用:

result_image = cv2.rectangle(image, (int(xmin), int(ymin)), (int(xmax),int(ymax)), (0,255,0), 8)

【讨论】:

  • 这也是重叠的矩形
猜你喜欢
  • 2023-04-01
  • 2017-03-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 2017-01-15
  • 2010-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多