3 #include <boost/lexical_cast.hpp> 4 #include <opencv2/highgui/highgui.hpp> 5 #include <opencv2/imgproc/imgproc.hpp> 44 , label_format_x_ (
"x=%f" )
45 , label_format_y_ (
"y=%f" ) {
49 void Figure::setLabel (
const std::string &label_format_x,
const std::string &label_format_y ) {
68 if ( view.empty() )
return;
69 view_.create ( view.cols, view.rows, CV_8UC3 );
70 int depth = view.depth(), cn = view.channels();
71 int type = CV_MAKETYPE ( depth, cn );
72 if ( type == CV_8UC3 ) {
73 view.copyTo (
view_ );
74 }
else if ( ( view.channels() == 1 ) && ( view.depth() == CV_8U ) ) {
75 cv::cvtColor ( view,
view_, CV_GRAY2BGR );
79 void Figure::init (
int width_pixel,
int height_pixel,
double min_x,
double max_x,
double min_y,
double max_y,
double rotation,
double grid_scale_y,
double grid_scale_x,
const std::string &background_image ) {
151 cv::Point pi =
w2m ( p ).
cv();
152 if ( ( pi.x < 0 ) || ( pi.x >= view.cols ) || ( pi.y < 0 ) || ( pi.y >= view.rows ) )
return;
153 cv::Vec3b &pixel = view.at<cv::Vec3b> ( pi );
154 pixel[0] = color[0], pixel[1] = color[1], pixel[2] = color[2];
165 symbol (
view_, p, radius, color, thickness, lineType );
173 void Figure::putText (
const std::string& text,
const Point2D &
p,
int fontFace,
double fontScale, cv::Scalar color,
int thickness,
int lineType,
bool bottomLeftOrigin ) {
174 putText (
view_, text, p, fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin );
176 void Figure::putText ( cv::Mat &
view,
const std::string& text,
const Point2D &
p,
int fontFace,
double fontScale, cv::Scalar color,
int thickness,
int lineType,
bool bottomLeftOrigin ) {
177 cv::putText ( view, text,
w2m ( p ).
cv(), fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin );
180 void Figure::appendToView (
const cv::Mat& _mat,
const cv::Scalar& _colMin,
const cv::Scalar& _colMax, u_int8_t _truncateLayerVal ) {
183 CV_Assert ( _mat.depth() == CV_8U );
184 int channels = _mat.channels();
185 int nRows = _mat.rows;
186 int nCols = _mat.cols * channels;
188 uint8_t
const* p_s; cv::Vec3b* p_d;
189 for(
int i = 0; i < nRows; ++i) {
190 for (p_s = _mat.ptr<
const uint8_t>(i), p_d =
view().ptr<cv::Vec3b>(i); p_s != _mat.ptr<uint8_t>(i+1); p_d++, p_s++){
191 if ( (*p_d == cv::Vec3b(255,255,255) ) && (*p_s < 255 - _truncateLayerVal ) ) {
192 double scale = *p_s / (255. - (double)_truncateLayerVal);
193 *p_d = cv::Vec3b( _colMin[0] + scale * (_colMax[0] - _colMin[0]),
194 _colMin[1] + scale * (_colMax[1] - _colMin[1]),
195 _colMin[2] + scale * (_colMax[2] - _colMin[2]) );
void circle(T &map, const Point2D &p, int radius, const cv::Scalar &color, int thickness=1, int lineType=CV_AA) const
void init()
initializes the transformation matrices
Point2D point_ahead(double d=1.) const
void line(T &map, const Point2D &p0, const Point2D &p1, const cv::Scalar &color, int thickness=1, int lineType=CV_AA) const
Point2D w2m(const Point2D &src) const
const Point2D & position() const
Point2D & set(double x, double y)
const cv::Point_< double > & cv() const