Classes | Functions
util.h File Reference

Small helper functions. More...

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <iterator>
#include <vector>
#include <boost/property_tree/ptree.hpp>

Go to the source code of this file.

Classes

class  FpS
 Class to measure frames per second. More...
 

Functions

void laustracker_imshow (const string &windoname, const Mat &image)
 Like imshow(), resizes the image on smaller screens. More...
 
void laustracker_imshow_croped (const string &windoname, const Mat &image, vector< Point > rect)
 Like imshow(), resizes the image on smaller screens and crops the image if the labyrinth position is known. More...
 
double angle (Point pt1, Point pt2, Point pt0)
 Calculate the cosine between two vectors. More...
 
bool intersection (Point o1, Point p1, Point o2, Point p2, Point &r)
 Calculate the intersection point of two straight lines. More...
 
void scale_rect (vector< Point > &rect, int pixels=15)
 Scale a rectangle. More...
 
int countColor (cv::Mat image, int color=255)
 Count the number of pixels of a specified color within a image region. More...
 
string get_selfpath ()
 Get the path of the current executable. More...
 
string get_selfdir (bool debug=false)
 Determine the directory of the current executable. More...
 
float DotProductPoints (Point2f const &a, Point2f const &b, Point2f const &c)
 Calculate the dot product of three points. More...
 
float CrossProductPoints (Point2f const &a, Point2f const &b, Point2f const &c)
 Calculate the cross product of three points. More...
 
float DistancePointPoint (Point2f const &a, Point2f const &b)
 Calculate the distance between two points. More...
 
float DistanceLinePoint (Point2f const &a, Point2f const &b, Point2f const &c, bool isSegment)
 Calculate the Distance between a straight line a a point. More...
 
Point2f centerPointPoint (Point2f a, Point2f b)
 Calculate the center point between two points. More...
 
float degrees (float radians)
 Convert radians to degrees. More...
 
template<typename T >
std::vector< T > to_array (const std::string &s)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const std::vector< T > &v)
 
Scalar get_gimp_color (boost::property_tree::ptree conf, string color_name)
 Get a HSV color from a Boost property_tree and convert the color from Gimp's color space into OpenCV's color space. More...
 

Detailed Description

Small helper functions.

Definition in file util.h.

Function Documentation

double angle ( Point  pt1,
Point  pt2,
Point  pt0 
)

Calculate the cosine between two vectors.

The angle gets spanned from pt0 to pt1 and from pt0 to pt2.

Parameters
pt0Origin
pt1First point
pt2Second point
Point2f centerPointPoint ( Point2f  a,
Point2f  b 
)

Calculate the center point between two points.

Parameters
aPoint A
bPoint B
Returns
Center point
int countColor ( cv::Mat  image,
int  color = 255 
)

Count the number of pixels of a specified color within a image region.

1 Mat roi = white_img(rois[i]);
1 int whitecount = countColor(roi, 255);
Parameters
imageImage or ROI
colorColor: 0 for black, 255 for white
float CrossProductPoints ( Point2f const &  a,
Point2f const &  b,
Point2f const &  c 
)

Calculate the cross product of three points.

float degrees ( float  radians)

Convert radians to degrees.

Parameters
radiansAngle in radians
Returns
Angle in degrees
float DistanceLinePoint ( Point2f const &  a,
Point2f const &  b,
Point2f const &  c,
bool  isSegment 
)

Calculate the Distance between a straight line a a point.

float DistancePointPoint ( Point2f const &  a,
Point2f const &  b 
)

Calculate the distance between two points.

Parameters
aPoint A
bPoint B
Returns
Distance
float DotProductPoints ( Point2f const &  a,
Point2f const &  b,
Point2f const &  c 
)

Calculate the dot product of three points.

Scalar get_gimp_color ( boost::property_tree::ptree  conf,
string  color_name 
)

Get a HSV color from a Boost property_tree and convert the color from Gimp's color space into OpenCV's color space.

Parameters
confBoost property_tree
color_nameName of the color to read
Returns
cv::Scalar with HSV color
string get_selfdir ( bool  debug = false)

Determine the directory of the current executable.

Parameters
debugPrint the path to stdout.
Returns
Directory of the current executable.
string get_selfpath ( )

Get the path of the current executable.

Returns
Name of the executable with path
bool intersection ( Point  o1,
Point  p1,
Point  o2,
Point  p2,
Point &  r 
)

Calculate the intersection point of two straight lines.

Parameters
o1First point of the first straight line.
p1Second point of the first straight line.
o2First point of the second straight line.
p2Second point of the second straight line.
rReference of a Point to store the intersection.
Returns
false, if there is no intersection
void laustracker_imshow ( const string &  windoname,
const Mat &  image 
)

Like imshow(), resizes the image on smaller screens.

Parameters
windonameWindow title
imageImage to show
void laustracker_imshow_croped ( const string &  windoname,
const Mat &  image,
vector< Point >  rect 
)

Like imshow(), resizes the image on smaller screens and crops the image if the labyrinth position is known.

Parameters
windonameWindow title
imageImage to show
void scale_rect ( vector< Point > &  rect,
int  pixels = 15 
)

Scale a rectangle.

Parameters
rectVector of four points
pixelsNumber of pixels to increase/decrease the rectangle.