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;
70 int depth =
view.depth(), cn =
view.channels();
71 int type = CV_MAKETYPE ( depth, cn );
72 if ( type == CV_8UC3 ) {
74 }
else if ( (
view.channels() == 1 ) && (
view.depth() == CV_8U ) ) {
75 cv::cvtColor (
view,
view_, cv::COLOR_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 ) {
110 cv::putText (
background_, txt,
w2m ( p0 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
white, 3, cv::LINE_AA );
111 cv::putText (
background_, txt,
w2m ( p0 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
gray, 1, cv::LINE_AA );
114 cv::putText (
background_, txt,
w2m ( p1 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
white, 3, cv::LINE_AA );
115 cv::putText (
background_, txt,
w2m ( p1 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
gray, 1, cv::LINE_AA );
130 cv::putText (
background_, txt,
w2m ( p0 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
white, 3, cv::LINE_AA );
131 cv::putText (
background_, txt,
w2m ( p0 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
gray, 1, cv::LINE_AA );
134 cv::putText (
background_, txt,
w2m ( p1 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
white, 3, cv::LINE_AA );
135 cv::putText (
background_, txt,
w2m ( p1 ).
cv(), cv::FONT_HERSHEY_PLAIN, 0.6,
gray, 1, cv::LINE_AA );
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 );
168 void Figure::symbol ( cv::Mat &view,
const Pose2D &
p,
double radius,
const cv::Scalar &color,
int thickness,
int lineType ) {
170 line (
p.position(),
p.point_ahead ( 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]) );