擅长:python、mysql、java
<p>A<strong>简单的方式</p>
<p><a href="https://i.stack.imgur.com/URk9l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/URk9l.png" alt="example"/></a>
(图像未按比例绘制)</p>
<pre class="lang-py prettyprint-override"><code>from shapely.geometry import Polygon
def calculate_iou(box_1, box_2):
poly_1 = Polygon(box_1)
poly_2 = Polygon(box_2)
iou = poly_1.intersection(poly_2).area / poly_1.union(poly_2).area
return iou
box_1 = [[511, 41], [577, 41], [577, 76], [511, 76]]
box_2 = [[544, 59], [610, 59], [610, 94], [544, 94]]
print(calculate_iou(box_1, box_2))
</code></pre>
<p>结果将是<code>0.138211...</code>,这意味着<code>13.82%</code>。</p>