7 #include <opencv2/opencv.hpp>
8 #include <vision_module/Tools/Parameters.hpp>
9 #include <vision_module/Tools/LineSegment.hpp>
10 #include <boost/timer/timer.hpp>
16 #define HAF_LOG_THROTTLE(rate, level, name, ...) \
19 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
20 static double last_hit = 0.0; \
21 ::ros::WallTime now = ::ros::WallTime::now(); \
22 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(last_hit + rate <= now.toSec())) \
24 last_hit = now.toSec(); \
25 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
29 #define HAF_INFO_THROTTLE(rate, ...) HAF_LOG_THROTTLE(rate, ::ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
30 #define HAF_WARN_THROTTLE(rate, ...) HAF_LOG_THROTTLE(rate, ::ros::console::levels::Warn, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
31 #define HAF_ERROR_THROTTLE(rate, ...) HAF_LOG_THROTTLE(rate, ::ros::console::levels::Error, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
32 #define HAF_DEBUG_THROTTLE(rate, ...) HAF_LOG_THROTTLE(rate, ::ros::console::levels::Debug, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
34 #define min_n(a,b) ((a) < (b) ? (a) : (b))
35 #define max_n(a,b) ((a) > (b) ? (a) : (b))
36 #define boundry_n(n,a,b) {n=min_n(b,n);n=max_n(a,n);}
37 #define DB() printf("Line number %d in file %s\n", __LINE__, __FILE__)
38 #define DT() boost::timer::auto_cpu_timer tmpAutoTimer
48 CircleC(cv::Point2f Center,
float Radius):Center(Center),Radius(Radius)
52 CircleC(
const CircleC &_in):Center(_in.Center),Radius(_in.Radius)
58 CircleC mergeCircleC(CircleC A, CircleC B);
59 bool hasIntersection(CircleC A, CircleC B);
60 bool lineFormIntersectionWithCircleC(
LineSegment l, CircleC c, Point2f &p1, Point2f &p2);
62 cv::Rect CircleCToRect(CircleC circ);
63 CircleC RectToCircleC(cv::Rect rec);
64 void RotateAroundPoint(Point2d pQuery,
double alpha, Point2d &res);
65 void RotateCoordinateAxis(
double alpha, Point2d p, Point2d &res);
66 double Radian2Degree(
double r);
67 double Degree2Radian(
double d);
68 void lowPass(Point3d newrec, Point3d &res,
double coef = 0.01);
69 void lowPass(Point2d newrec, Point2d &res,
double coef = 0.01);
70 void lowPass(
double newrec,
double &res,
double coef = 0.01);
71 void lowPassAngleDegree180(
double newrec,
double &res,
double coef = 0.01);
72 double AngleSubDegree180(
double first,
double second);
73 Point2d GetCenterMinBounding(vector<Point> con);
74 Point2d GetCenterBoundingRec(vector<Point> con);
75 double GetDistance(Point2d p);
76 float GetDistance(Point2f p);
77 double GetDistance(Point2d p, Point2d p2);
81 Mat get_hogdescriptor_visual_image(Mat& origImg,
82 vector<float>& descriptorValues, Size winSize, Size cellSize,
83 int scaleFactor,
double viz_factor);
91 cv::Point2f RotateCoordinateAxis(
double alpha, cv::Point2f p);
95 cv::Point2f RotateAroundPoint(cv::Point2f pQuery,
double alpha,
101 cv::Point2f RotateAroundPoint(cv::Point2f pQuery,
double alpha);
104 int Bottom(Rect rec);
106 cv::Scalar pinkColor();
107 cv::Scalar pinkMeloColor();
110 Scalar darkOrangeColor();
111 Scalar redMeloColor();
113 Scalar yellowColor();
115 Scalar blueMeloColor();
117 cv::Scalar blackGary();
120 Point2d GetCenter(Rect rec);
121 bool MinXPoint(vector<Point2f> con, Point2f &res);
122 bool MinYPoint(vector<Point2f> con, Point2f &res);
123 bool MaxXPoint(vector<Point2f> con, Point2f &res);
124 bool MaxYPoint(vector<Point2f> con, Point2f &res);
125 bool MinXPoint(vector<Point> con, Point &res);
126 bool MinYPoint(vector<Point> con, Point &res);
127 bool MaxXPoint(vector<Point> con, Point &res);
128 bool MaxYPoint(vector<Point> con, Point &res);
130 double AngleBetween0to180(RotatedRect calculatedRect);
131 vector<Point> convert(
const vector<Point2f> &con, vector<Point> res);
133 vector<Point2f> convert(
const vector<Point> &con, vector<Point2f> res);
134 Point convert(
const Point2f &in);
135 Point2f convert(
const Point &in);
138 bool checkBox_Size_Scale_Angle(
const vector<Point2f> &con,
hsvRangeC type);
140 float DistanceFromLineSegment(
LineSegment line, Point2f p);
141 double Distance2point(Point2f begin, Point2f end);
143 Point2f GetAverage(Point2f p0, Point2f p1);
144 Point2f GetWeigthedAverage(Point2f p0, Point2f p1,
float w0,
float w1);
145 float GetWeigthedAverage(
float p0,
float p1,
float w0,
float w1);
146 Point2f AddP(Point2f a,
float b);
148 double CorrectAngleDegree360(
double x);
150 double CorrectAngleDegree180(
double x);
152 double CorrectAngleRadian360(
double x);
154 double CorrectAngleRadian180(
double x);
156 float AngleDiffDegree180(
float first,
float second);
158 float AngleDiffRadian180(
float first,
float second);
160 bool MergeLinesMax(vector<LineSegment> resLinesReal,
double maxDegree,
161 double maxDistance, vector<LineSegment> &clusteredLines, Rect box,
162 bool useBounding =
false);
164 bool MergeLinesOnce(vector<LineSegment> resLinesReal,
double maxDegree,
165 double maxDistance, vector<LineSegment> &clusteredLines, Rect box,
166 bool useBounding =
false);
167 void drawLine(Mat img, Vec4f line,
int thickness, Scalar color);
168 bool calcHist3Channels(cv::Mat &colorMatRoi, cv::Mat &justObjMask,
169 cv::Mat hist_base[3]);
171 cv::Rect clipRect(cv::Rect _in, cv::Rect _box);
172 bool minDimentionRect(
int _min, cv::Rect &_in);
173 bool maxDimentionRect(
int _max, cv::Rect &_in);
174 bool mergeRect(cv::Rect &_in, cv::Rect _in2);
175 cv::Rect asymetricScaleRec(
double _xLeftRatio,
double _xRightRatio,
176 double _yTopRatio,
double _yDownRatio, cv::Rect _in);
177 cv::Rect asymetricScaleRec(
double _xLeftRatio,
double _xRightRatio,
178 double _yTopRatio,
double _yDownRatio, cv::Rect _in, cv::Rect _box);
179 cv::Rect scaleRec(
double _xRatio,
double _yRatio, cv::Rect _in);
180 cv::Rect scaleRec(
double _xRatio,
double _yRatio, cv::Rect _in, cv::Rect _box);
182 template<
class _Tp>
bool write2File(
const string& filename,
183 const vector<_Tp> &items)
187 FileStorage fs(params.configPath + filename, FileStorage::WRITE);
192 fs <<
"Count" << (int) items.size();
194 for (
size_t i = 0; i < items.size(); ++i)
196 oss <<
"Element" << i;
197 fs << oss.str() << items[i];
204 }
catch (Exception &e)
206 ROS_ERROR(
"Problem writing %s |-> what = %s", filename.c_str(),
212 template<
class _Tp>
bool readFromFile(
const string& filename,
217 FileStorage fs(params.configPath + filename, FileStorage::READ);
221 num = (int) fs[
"Count"];
223 for (
int i = 0; i < num; ++i)
225 oss <<
"Element" << i;
226 fs[oss.str()] >> myVec[i];
232 }
catch (Exception &e)
234 ROS_ERROR(
"Problem parsing %s |-> what = %s", filename.c_str(),
240 template<
class _Tp>
bool add2File(
const string& filename,
const _Tp &item)
243 bool res = readFromFile(filename, readVec);
244 readVec.push_back(item);
245 res &= write2File(filename, readVec);
250 string to_string(T pNumber)
252 ostringstream oOStrStream;
253 oOStrStream << pNumber;
254 return oOStrStream.str();
A class representing line segments.
Definition: LineSegment.hpp:17
HSV range class.
Definition: Parameters.hpp:126