如何计算Python OpenCV中边界盒的质心
我正在做推理和检测手,我需要计算检测到的手的边界框的质心。
以下是它的坐标:
left = 215
bottom = 447
right = 325
top = 367
这就是我现在绘制矩形
cv2.rectangle(frame, (int(obj.Left), int(obj.Bottom)), (int(obj.Right), int(obj.Top)), (0, 0, 255), 2)
以计算边界框的质心的方式,我使用以下代码线:
w = int(obj.Right - obj.Left)
h = int(obj.Bottom - obj.Top)
cx = int(obj.Top + h/2)
cy = int(obj.Left + w/2)
print(cx, cy)
因此,首先,我正在计算边界框的宽度和高度。然后将高度和宽度除以2,然后将它们分别添加到顶部和左侧以计算质心。但这似乎无法正常工作,因为您可以看到白点(以红色圆圈为代表)远离被检测到的手。
我该如何改进?
I am doing inference and detecting hands and I need to calculate the centroid of the bounding box of the detected hand.
Below is its coordinates:
left = 215
bottom = 447
right = 325
top = 367
and this is how I am drawing the rectangle
cv2.rectangle(frame, (int(obj.Left), int(obj.Bottom)), (int(obj.Right), int(obj.Top)), (0, 0, 255), 2)
Now in order to calculate the centroid of the bounding box, I am using below lines of code:
w = int(obj.Right - obj.Left)
h = int(obj.Bottom - obj.Top)
cx = int(obj.Top + h/2)
cy = int(obj.Left + w/2)
print(cx, cy)
So first I am calculating the width and height of the bounding box. Then dividing the height and width by 2 and adding them to top and left respectively to calculate the centroid. But this doesn't seems to be working as you can see the white dot (represented in red circle) is far away from detected hand.
How can I improve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论