mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 18:22:48 +08:00
Added function to get Y value for a point on a line segment
This commit is contained in:
@@ -439,6 +439,12 @@ int levenshteinDistance (const std::string &s1, const std::string &s2, int max)
|
|||||||
return slope * (x - p2.x) + p2.y;
|
return slope * (x - p2.x) + p2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float LineSegment::getXPointAt(float y)
|
||||||
|
{
|
||||||
|
float y_intercept = getPointAt(0);
|
||||||
|
return (y - y_intercept) / slope;
|
||||||
|
}
|
||||||
|
|
||||||
Point LineSegment::closestPointOnSegmentTo(Point p)
|
Point LineSegment::closestPointOnSegmentTo(Point p)
|
||||||
{
|
{
|
||||||
float top = (p.x - p1.x) * (p2.x - p1.x) + (p.y - p1.y)*(p2.y - p1.y);
|
float top = (p.x - p1.x) * (p2.x - p1.x) + (p.y - p1.y)*(p2.y - p1.y);
|
||||||
|
@@ -55,6 +55,7 @@ namespace alpr
|
|||||||
bool isPointBelowLine(cv::Point tp);
|
bool isPointBelowLine(cv::Point tp);
|
||||||
|
|
||||||
float getPointAt(float x);
|
float getPointAt(float x);
|
||||||
|
float getXPointAt(float y);
|
||||||
|
|
||||||
cv::Point closestPointOnSegmentTo(cv::Point p);
|
cv::Point closestPointOnSegmentTo(cv::Point p);
|
||||||
|
|
||||||
|
@@ -26,6 +26,11 @@ TEST_CASE( "LineSegment Test", "[2d primitives]" ) {
|
|||||||
REQUIRE( flat_horizontal.midpoint().x == 11 );
|
REQUIRE( flat_horizontal.midpoint().x == 11 );
|
||||||
REQUIRE( flat_horizontal.getPointAt(11) == 1 );
|
REQUIRE( flat_horizontal.getPointAt(11) == 1 );
|
||||||
|
|
||||||
|
LineSegment rising_45(1,1, 5,5);
|
||||||
|
|
||||||
|
REQUIRE( rising_45.getPointAt(3) == 3 );
|
||||||
|
REQUIRE( rising_45.getXPointAt(3) == 3 );
|
||||||
|
|
||||||
// Test distance between points calculation
|
// Test distance between points calculation
|
||||||
REQUIRE( distanceBetweenPoints(Point(10,10), Point(20,20)) == Approx(14.1421) );
|
REQUIRE( distanceBetweenPoints(Point(10,10), Point(20,20)) == Approx(14.1421) );
|
||||||
REQUIRE( distanceBetweenPoints(Point(-5,10), Point(20,-12)) == Approx(33.3017) );
|
REQUIRE( distanceBetweenPoints(Point(-5,10), Point(20,-12)) == Approx(33.3017) );
|
||||||
|
Reference in New Issue
Block a user