简体   繁体   English

找到边界框的中心

[英]Find center of bounding box

So I was trying to extract center of this bounding box, Here is the example of what I get所以我试图提取这个边界框的中心,这是我得到的例子

...
dst = cv2.perspectiveTransform(pts, M)
print(dst)

Output Output

[[[548.70825 259.41586]]

 [[545.6091  334.8546 ]]

 [[623.4297  333.46515]]

 [[620.9301  260.8716 ]]]

I want to find the center of the dst variable, thanks for the help mate!我想找到 dst 变量的中心,感谢您的帮助!

If You have bounding box with points (p1, p2, p3, p4) with coordinates如果您有带坐标点(p1, p2, p3, p4)的边界框

((x1, y1),(x2, y2),(x3, y3),(x4, y4)) , where points are accordingly ((x1, y1),(x2, y2),(x3, y3),(x4, y4)) ,其中点相应

p1-> left top corner, p2-> left bottom corner, p3-> right bottom corner, p4-> right top corner as I believe is in Your case, You can treat the center of the bounding box as the intersection of the diagonals. p1-> left top corner, p2-> left bottom corner, p3-> right bottom corner, p4-> right top corner ,我相信在您的情况下,您可以将边界框的中心视为对角线的交点.

You need to find equations for lines that diagonals are lying on: Y1 = a1*X1+b1; Y2 = a2*X2+b2您需要找到对角线所在的直线的方程式: Y1 = a1*X1+b1; Y2 = a2*X2+b2 Y1 = a1*X1+b1; Y2 = a2*X2+b2 . Y1 = a1*X1+b1; Y2 = a2*X2+b2 Basically You have to calculate a1, b1, a2, b2 coefficients.基本上,您必须计算a1, b1, a2, b2系数。 It can be done easily, since You have the points.它可以很容易地完成,因为你有积分。

After that You should find coordinates of the common point so Y0 = a1*X0+b1; Y0 = a2*X0+b2之后你应该找到公共点的坐标所以Y0 = a1*X0+b1; Y0 = a2*X0+b2 Y0 = a1*X0+b1; Y0 = a2*X0+b2 . Y0 = a1*X0+b1; Y0 = a2*X0+b2 In that case:在这种情况下:

(x0, y0) = ((b2-b1)/(a1-a2), a2*(b2-b1)/(a1-a2)+b2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM