CVB++ 15.0
regression.hpp
1#pragma once
2
3#if defined _WIN32
4
5# include "../_cexports/c_foundation.h"
6
7# include "../global.hpp"
8# include "../exception.hpp"
9# include "../circle.hpp"
10# include "../ellipse.hpp"
11# include "../line_2d.hpp"
12# include "../_detail/detail_pixel_list.hpp"
13# include "../point_2d.hpp"
14# include "../angle.hpp"
15
16namespace Cvb
17{
18 CVB_BEGIN_INLINE_NS
19
21 namespace Foundation
22 {
23
25
29 namespace Regression
30 {
32
38 template <class RANGE>
39 inline typename TypedRange<Circle, Point2D<double>, RANGE>::type CircleRegression(const RANGE &points)
40 {
41 auto pixelList = Internal::PixelList::FromPoints(points);
42
43 double x, y, radius;
44 CVB_CALL_CAPI_CHECKED(CalculateCircleRegression(pixelList->Handle(), x, y, radius));
45 return Circle(Point2D<double>(x, y), radius);
46 }
47
49
55 template <class RANGE>
56 inline typename TypedRange<Ellipse, Point2D<double>, RANGE>::type EllipseRegression(const RANGE &points)
57 {
58 auto pixelList = Internal::PixelList::FromPoints(points);
59
60 double x, y, radiusA, radiusB, rot;
61 CVB_CALL_CAPI_CHECKED(CalculateEllipseRegression(pixelList->Handle(), x, y, radiusA, radiusB, rot));
62 return Ellipse(Point2D<double>(x, y), radiusA, radiusB, Angle::FromDegrees(rot));
63 }
64
66
72 template <class RANGE>
73 inline typename TypedRange<Line2D, Point2D<double>, RANGE>::type LineRegression(const RANGE &points)
74 {
75 auto pixelList = Internal::PixelList::FromPoints(points);
76
77 auto hLine = CVB_CALL_CAPI(CreateLine2DByRegression(pixelList->Handle()));
78 ReleaseObjectGuard hLineHolder(hLine);
79
80 double distance;
81 CVB_CALL_CAPI_CHECKED(GetLine2DOriginDistance(hLine, distance));
82 CExports::VECTOR2D hVector;
83 CVB_CALL_CAPI_CHECKED(GetLine2DNormalVector(hLine, hVector));
84 ReleaseObjectGuard hVectorHolder(hVector);
85
86 double vectX, vectY;
87 CVB_CALL_CAPI_CHECKED(GetVector2DCartesian(hVector, vectX, vectY));
88
89 return Line2D(Point2D<double>(vectX, vectY), distance);
90 }
91
92 } /* namespace Regression */
93
97
98 } /* namespace Foundation */
99 CVB_END_INLINE_NS
100} /* namespace Cvb */
101
102#endif
static Angle FromDegrees(double deg, bool trim=false) noexcept
Create an angle in degrees.
Definition angle.hpp:25
Class representing a circle.
Definition circle.hpp:19
Class representing an ellipse.
Definition ellipse.hpp:20
Object representing an infinite line in 2 dimensional space.
Definition line_2d.hpp:16
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
cvbres_t CalculateEllipseRegression(PIXELLIST pl, double &centerX, double &centerY, double &radiusA, double &radiusB, double &rotation)
cvbres_t CalculateCircleRegression(PIXELLIST pl, double &centerX, double &centerY, double &radius)
LINE2D CreateLine2DByRegression(PIXELLIST RegressionList)
cvbres_t GetLine2DNormalVector(LINE2D Line, VECTOR2D &Vector)
cvbres_t GetVector2DCartesian(VECTOR2D Input, double &X, double &Y)
cvbres_t GetLine2DOriginDistance(LINE2D Line, double &Distance)
Various regression functions.
Definition regression.hpp:30
TypedRange< Line2D, Point2D< double >, RANGE >::type LineRegression(const RANGE &points)
Create a line, that fits best into a collection of points.
Definition regression.hpp:73
TypedRange< Ellipse, Point2D< double >, RANGE >::type EllipseRegression(const RANGE &points)
Create an ellipse, that fits best into a collection of points.
Definition regression.hpp:56
TypedRange< Circle, Point2D< double >, RANGE >::type CircleRegression(const RANGE &points)
Create a circle, that fits best into a collection of points.
Definition regression.hpp:39
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17