gpt4 book ai didi

python - 如何知道边界框(矩形)是否位于另一个边界框(矩形)内?

转载 作者:行者123 更新时间:2023-12-02 17:01:08 28 4
gpt4 key购买 nike

我正在尝试将外框内的框(坐标)放入。我已经使用交集联合方法完成了工作,并且我希望其他方法也可以这样做。 enter image description here

另外,能否请您告诉我如何比较这两个内盒?

最佳答案

通过比较边界框和内部框的左上角和右下角的坐标,很容易知道后者是否在前者内部。

以下代码是一个仅包含一个边界框和一个内部框的简单示例:

# Bounding box
boundb = {
'x': 150,
'y': 150,
'height': 50,
'width': 100
}

# Inner box
innerb = {
'x': 160,
'y': 160,
'height': 25,
'width': 25
}

# If top-left inner box corner is inside the bounding box
if boundb['x'] < innerb['x'] and boundb['y'] < innerb['y']:
# If bottom-right inner box corner is inside the bounding box
if innerb['x'] + innerb['width'] < boundb['x'] + boundb['width'] \
and innerb['y'] + innerb['height'] < boundb['y'] + boundb['height']:
print('The entire box is inside the bounding box.')
else:
print('Some part of the box is outside the bounding box.')

关于python - 如何知道边界框(矩形)是否位于另一个边界框(矩形)内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60949898/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com