Update rotatedRectangleIntersection function to calculate near to origin#19842
Update rotatedRectangleIntersection function to calculate near to origin#19842alalek merged 6 commits intoopencv:3.4from
Conversation
In the function that sets the points of a RotatedRect, the types should be double in order to keep the precision when dealing with RotatedRects that are defined far from the origin. This commit solves the problem in some assertions from rotatedRectangleIntersection when dealing with rectangles far from origin.
|
does this actually make a difference? it only applies double precision to the calculation itself but the result is still just FP32. the demo code uses values like 4002326. there is simply not enough precision to go around (6-7 digits). >>> [cx, cy, w, h, angle] = np.float32([ 246805.033 , 4002326.94 , 26.40587, 6.20026, -62.10156])
>>> _angle = angle * pi / 180
>>> a = np.sin(_angle)*0.5
>>> b = np.cos(_angle)*0.5
>>> f = np.float32; cx - f(a)*h - f(b)*w; cy + f(b)*h - f(a)*w
246801.6
4002340.2
>>> f = np.float64; cx - f(a)*h - f(b)*w; cy + f(b)*h - f(a)*w
246801.59334828143
4002340.119037186 |
Yes. When testing the code provided by @jbwintergest here: #19824: when the function This is the content of Before: After: When the function |
|
jenkins cn please retry a build |
|
@gasparitiago, thank you for the contribution! I wonder if you could also modify |
|
Hello @vpisarev, I'm doing it. When I finish I will update this PR and let you know. To be honest I will need some help on how to test the solution. |
|
@vpisarev can you take a look at my last commit? |
This commit changes the rotatedRectangleIntersection function in order to calculate the intersection of two rectangles considering that they are shifted near the coordinates origin (0, 0). This commit solves the problem in some assertions from rotatedRectangleIntersection when dealing with rectangles far from origin.
alalek
left a comment
There was a problem hiding this comment.
Looks good!
Please update PR's title and description before merge.

This commit changes the rotatedRectangleIntersection function in order to calculate the intersection of two rectangles considering that they are shifted near the coordinates origin (0, 0).
This commit solves the problem in some assertions from rotatedRectangleIntersection when dealing with rectangles far from origin.
Original issue: #19824
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.