41 #include <opencv2/core.hpp>
47 const double PI = 3.14159265;
53 inline int ALVAR_EXPORT
56 return (v < 0 ? -1 : 1);
63 inline double ALVAR_EXPORT
66 return v * (180 / PI);
73 inline double ALVAR_EXPORT
76 return v * (PI / 180);
82 template <
class C,
class D =
int>
83 struct ALVAR_EXPORT
Point :
public C
90 Point(
int vx = 0,
int vy = 0)
95 Point(
double vx,
double vy)
117 template <
class Po
intType>
121 return ((p1.x - p2.x) * (p1.x - p2.x)) + ((p1.y - p2.y) * (p1.y - p2.y));
130 int ALVAR_EXPORT
dot(
const cv::Point &A,
const cv::Point &B,
const cv::Point &C);
137 int ALVAR_EXPORT
cross(
const cv::Point &A,
const cv::Point &B,
const cv::Point &C);
143 double ALVAR_EXPORT
distance(
const cv::Point &A,
const cv::Point &B);
164 double ALVAR_EXPORT
angle(
const cv::Point &A,
168 int isDirectionDependent);
179 int isClosedPolygon);
188 cv::RotatedRect & ellipse_box);
190 int ALVAR_EXPORT exp_filt2(std::vector<double> &v, std::vector<double> &ret,
bool clamp);
199 inline int ALVAR_EXPORT
200 diff(
const std::vector<C> &v, std::vector<C> &ret)
205 }
else if (v.size() > 1) {
206 ret.push_back(v.at(1) - v.at(0));
207 for (
size_t i = 1; i < v.size(); ++i) {
208 ret.push_back(v.at(i) - v.at(i - 1));
211 return int(ret.size());
222 std::vector<int> & corners,
228 void ALVAR_EXPORT
out_matrix(
const cv::Mat &m,
const char *name);
237 double ALVAR_EXPORT
Limit(
double val,
double min_val,
double max_val);
266 std::map<Index, int> bins;
267 std::vector<int> dim_binsize;
268 int DimIndex(
int dim,
double val);
269 double DimVal(
int dim,
int index);
278 void Inc(
double dim0,
double dim1 = 0,
double dim2 = 0);
282 int GetMax(
double *dim0,
double *dim1 = 0,
double *dim2 = 0);
291 std::map<Index, double> acc_dim0;
292 std::map<Index, double> acc_dim1;
293 std::map<Index, double> acc_dim2;
299 void Inc(
double dim0,
double dim1 = 0,
double dim2 = 0);
304 int GetMax(
double *dim0,
double *dim1 = 0,
double *dim2 = 0);
307 #if (_MSC_VER >= 1400)
309 STRCPY(
char *to, rsize_t size,
const char *src)
311 strcpy_s(to, size, src);
315 STRCPY(
char *to,
size_t size,
const char *src)
317 strncpy(to, src, size - 1);
374 std::string filename;
377 void * formatter_handle;
380 bool Descend(
const char *
id);
427 operator<<(C &serializable)
430 if (!SerializeClass(serializable) || !Output()) {
441 if (!Input() || !SerializeClass(serializable)) {
455 std::string s = serializable.SerializeId();
456 if (!Descend(s.c_str()) || !serializable.Serialize(
this) || !Ascend()) {
464 bool Serialize(
unsigned short &data,
const std::string &name);
466 bool Serialize(
unsigned long &data,
const std::string &name);
470 bool Serialize(std::string &data,
const std::string &name);
This file defines library export definitions, version numbers and build information.
This file implements the ALVAR exception class.
Class for N-dimensional Histograms.
void AddDimension(int binsize)
Add dimension with a binsize.
void Clear()
Clear the histogram.
void Inc(double dim0, double dim1=0, double dim2=0)
Increase the histogram for given dimensions.
int GetMax(double *dim0, double *dim1=0, double *dim2=0)
Get the maximum from the histogram This returns the value in the middle of the 'bin' instead of bin-n...
N-dimensional Histograms calculating also the subpixel average for max bin.
void Clear()
Clear the histogram.
void Inc(double dim0, double dim1=0, double dim2=0)
Increase the histogram for given dimensions.
int GetMax(double *dim0, double *dim1=0, double *dim2=0)
Get the maximum from the histogram This finds the maximum bin(s) and averages the original values con...
Class for serializing class content to/from file or std::iostream.
bool Serialize(cv::Mat &data, const std::string &name)
Method for serializing 'cv::Mat' data element. Used from your serializable class.
bool SerializeClass(C &serializable)
Method for serializing a serializable class. Used by operators << and >> .
Serialization(std::string _filename)
Constructor for serializing to/from specified filename.
bool Serialize(std::string &data, const std::string &name)
Method for serializing 'std::string' data element. Used from your serializable class.
bool Serialize(unsigned long &data, const std::string &name)
Method for serializing 'int' data element. Used from your serializable class.
Serialization(std::basic_iostream< char > &_stream)
Constructor for serializing any iostream (e.g. std::stringstream)
bool Serialize(int &data, const std::string &name)
Method for serializing 'int' data element. Used from your serializable class.
bool IsInput()
Method for checking if we are inputting or outputting. Can be used from your serializable class.
Serialization & operator>>(C &serializable)
Operator for reading a serializable class from the defined filename or std::iostream.
bool Serialize(unsigned short &data, const std::string &name)
Method for serializing 'int' data element. Used from your serializable class.
bool Serialize(double &data, const std::string &name)
Method for serializing 'double' data element. Used from your serializable class.
Serialization(std::basic_istream< char > &_stream)
Constructor for serializing any istream (e.g. std::cin)
Serialization(std::basic_ostream< char > &_stream)
Constructor for serializing any ostream (e.g. std::cout)
~Serialization()
Destructor.
void ALVAR_EXPORT out_matrix(const cv::Mat &m, const char *name)
Output OpenCV matrix for debug purposes.
int ALVAR_EXPORT find_zero_crossings(const std::vector< double > &v, std::vector< int > &corners, int offs=20)
Finds zero crossings of given vector elements (sequence).
double ALVAR_EXPORT distance(const cv::Point &A, const cv::Point &B)
Compute the distance from A to B.
double ALVAR_EXPORT linePointDist(const cv::Point &A, const cv::Point &B, const cv::Point &C, bool isSegment)
Computes the distance from point C to line (segment) AB.
double ALVAR_EXPORT Limit(double val, double min_val, double max_val)
Limits a number to between two values.
ALVAR_EXPORT Point< cv::Point > PointInt
The default integer point type.
ALVAR_EXPORT Point< cv::Point2d > PointDouble
The default double point type.
double ALVAR_EXPORT angle(const cv::Point &A, const cv::Point &B, const cv::Point &C, const cv::Point &D, int isDirectionDependent)
Computes the angle between lines AB and CD.
double PointSquaredDistance(PointType p1, PointType p2)
Returns the squared distance of two points.
double ALVAR_EXPORT Deg2Rad(const C &v)
Converts an angle from degrees to radians.
int ALVAR_EXPORT cross(const cv::Point &A, const cv::Point &B, const cv::Point &C)
Computes the cross product AB x AC.
int ALVAR_EXPORT dot(const cv::Point &A, const cv::Point &B, const cv::Point &C)
Computes dot product AB.BC.
double ALVAR_EXPORT polyLinePointDist(const std::vector< cv::Point > &points, const cv::Point &C, int *index, int isClosedPolygon)
Calculates minimum distance from Point C to Polygon whose points are in list PointList.
int ALVAR_EXPORT diff(const std::vector< C > &v, std::vector< C > &ret)
Calculates the difference between the consecutive vector elements.
int ALVAR_EXPORT Sign(const C &v)
Returns the sign of a number.
double ALVAR_EXPORT Rad2Deg(const C &v)
Converts an angle from radians to degrees.
void ALVAR_EXPORT FitCVEllipse(const std::vector< PointDouble > &points, cv::RotatedRect &ellipse_box)
Uses OpenCV routine to fit ellipse to a vector of points.
Class for N-dimensional index to be used e.g. with STL maps.
std::vector< int > val
The indices for each dimension are stored in val (last being the most significant)
Index(int a)
Constructor for 1D index.
Index(int a, int b, int c)
Constructor for 3D index.
Index(int a, int b)
Constructor for 2D index.
bool operator<(const Index &index) const
Operator used for sorting the multidimensional indices (last dimension being the most significant)
Simple Point class meant to be inherited from OpenCV point-classes. For example: Point<cv::Point2d> p...
D val
Additional value can be related to the point.