-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a missing constructor for struct RotatedRect
from three vertex points
#1576
Conversation
Here's a test: for (var i = 0f; i < 360; i += 1)
{
var rt1 = new RotatedRect(new(50.5f, 50.5f), new(100.5, 100.5), i);
var p = rt1.Points();
var rt2 = new RotatedRect(p[0], p[1], p[2]);
var tolerance = 0.0001;
if (Math.Abs(rt2.Angle - rt1.Angle) > tolerance
|| Math.Abs(rt2.Center.X - rt1.Center.X) > tolerance
|| Math.Abs(rt2.Center.Y - rt1.Center.Y) > tolerance
|| Math.Abs(rt2.Size.Width - rt1.Size.Width) > tolerance
|| Math.Abs(rt2.Size.Height - rt1.Size.Height) > tolerance)
{
Console.WriteLine("1 rtAngle={0} rtCenterX={1} rtCenterY={2} rtWidth={3} rtHeight={4}\n"
+ "2 rtAngle={5} rtCenterX={6} rtCenterY={7} rtWidth={8} rtHeight={9}\n",
rt1.Angle, rt1.Center.X, rt1.Center.Y, rt1.Size.Width, rt1.Size.Height,
rt2.Angle, rt2.Center.X, rt2.Center.Y, rt2.Size.Width, rt2.Size.Height);
}
} The angle will wrapping around from -45 to 44 degrees, and restart until the original angle reach 0:
I don't know is this comes from the original implement or just in my own translation. |
return s; | ||
} | ||
// check that given sides are perpendicular | ||
Debug.Assert(Math.Abs(Ddot(vecs[0], vecs[1])) * a <= fltEpsilon * 9 * x * (Cv2.Norm(vecs[0]) * Cv2.Norm(vecs[1]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert will fail when providing following points: new RotatedRect(new(403.2502, 109.6314), new(505.6677, 349.0594), new(271.8243, 446.3848))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name 'Debug' does not exist in the current context
How do we do asserts in methods translated from cpp?
IIRC, OpenCV assert will always throw runtime cpp exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using System.Diagnostics; // Add this!!
...
Debug.Assert(...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May we use global using
?
Thank you. Can you fix the CI errors? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GH Actions
return s; | ||
} | ||
// check that given sides are perpendicular | ||
Debug.Assert(Math.Abs(Ddot(vecs[0], vecs[1])) * a <= fltEpsilon * 9 * x * (Cv2.Norm(vecs[0]) * Cv2.Norm(vecs[1]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name 'Debug' does not exist in the current context
How do we do asserts in methods translated from cpp?
IIRC, OpenCV assert will always throw runtime cpp exception.
I will fix the CI error on my end. Thank you! |
Have you found out what causes this inconsistency compared to the original |
I have been checking your code since I merged this PR into master and have come to understand the problem. I don't know the cause yet. One thing I know is that Math.PI is less accurate than CV_PI. |
fix #1575
or we may just delegate it to the native implement that already done in OpenCV.