-
-
Notifications
You must be signed in to change notification settings - Fork 56.3k
Closed
Labels
Description
System information (version)
- OpenCV => master
- Operating System / Platform => Linux 64 Bit
- Compiler => gcc
Detailed description
OpenCV RotatedRect intersection calculation currently uses float for intermediate variables. In some edge cases, the limited precision causes assertion problems inside intersection code:
CV_Assert( intersection.size() <= 8 );
The problem can be mitigated by doing all calculations in double precision as shown below:
float A = -vec2[j].y;
float B = vec2[j].x;
float C = -(A * pts2[j].x + B * pts2[j].y);
float s = A * x + B * y + C;
//Using float: xx = -1990.670654, yy = 1636.783203,A = 200.753662, B = -121.916260, C = 599184.937500, x = -2071.253906, y = 1504.090820, s = 0.000000
double A = -vec2[j].y;
double B = vec2[j].x;
double C = -(A * pts2[j].x + B * pts2[j].y);
double s = A * x + B * y + C;
//Using double: xx = -1990.670654, yy = 1636.783203,A = 200.753662, B = -121.916260, C = 599184.910076, x = -2071.253906, y = 1504.090820, s = -0.023922
Steps to reproduce
See above example.