'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
[[[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!
Solution 1:[1]
If You have bounding box with points (p1, p2, p3, p4) with coordinates
((x1, y1),(x2, y2),(x3, y3),(x4, y4)), where points are accordingly
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.
You need to find equations for lines that diagonals are lying on: Y1 = a1*X1+b1; Y2 = a2*X2+b2. Basically You have to calculate a1, b1, a2, b2 coefficients. 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. In that case:
(x0, y0) = ((b2-b1)/(a1-a2), a2*(b2-b1)/(a1-a2)+b2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
