35 #include <opencv2/core/core.hpp> 36 #include <opencv2/core/core_c.h> 37 #include <opencv2/opencv.hpp> 38 #include <opencv/cv.hpp> 49 double min_x,
double max_x,
50 double min_y,
double max_y,
double rotation ) {
51 init(width_pixel, height_pixel, min_x, max_x, min_y, max_y, rotation);
56 return mapLayers_.size();
61 mapLayers_.resize ( _n );
65 for(
size_t i = 0; i < mapLayers_.size(); i++){ mapLayers_[i].create ( width(), height(), CV_32FC1 ); clearLayer(i); }
69 for(
size_t i = 0; i < mapLayers_.size(); i++){ clearLayer(i); }
72 mapLayers_[_layer].setTo( 1 );
76 return mapLayers_[_layer];
79 return mapLayers_[_layer];
84 Point2D mapPos = w2m(_worldPos);
85 if ( !mapPos.
inside(0, 0, mapLayer(_layer).rows-1, mapLayer(_layer).cols-1 ) ) {
return -100; }
86 const double mapPos_row_d = mapPos.
y() , mapPos_col_d = mapPos.
x();
87 const int mapPos_row_i = int(mapPos_row_d), mapPos_col_i = int(mapPos_col_d);
90 switch ( _interpolationType ) {
92 retVal = mapLayer(_layer).at<float_t>( mapPos_row_i, mapPos_col_i );
97 const double f00 = mapLayer(_layer).at<float_t>(mapPos_row_i , mapPos_col_i );
98 const double f10 = mapLayer(_layer).at<float_t>(mapPos_row_i + 1, mapPos_col_i );
99 const double f01 = mapLayer(_layer).at<float_t>(mapPos_row_i , mapPos_col_i + 1);
100 const double f11 = mapLayer(_layer).at<float_t>(mapPos_row_i + 1, mapPos_col_i + 1);
102 const double mapPosRed_row = mapPos_row_d - mapPos_row_i, mapPosRed_col = mapPos_col_d - mapPos_col_i;
104 retVal = f00 * (1 - mapPosRed_row) * (1 - mapPosRed_col) +
105 f10 * mapPosRed_row * (1 - mapPosRed_col) +
106 f01 * (1 - mapPosRed_row) * mapPosRed_col +
107 f11 * mapPosRed_row * mapPosRed_col;
115 if ( d < threshold ) {
116 p = tanh ( ( 2*M_PI*-d ) /threshold+M_PI ) * 0.5 + 0.5;
122 if ( d < threshold ) {
129 Mat srcMap; srcMap.create ( width(), height(), CV_32FC1 ); srcMap.setTo ( 1 );
131 if(connectPoints){
for (
size_t i = 1; i < _pSrc.size(); i++ ) { line ( srcMap, _pSrc[i-1], _pSrc[i], colour, 8); } }
132 else {
for (
size_t i = 0; i < _pSrc.size(); i++ ) { circle ( srcMap, _pSrc[i], 1, colour, 1, 8); } }
133 computeDistanceField ( _mDst, srcMap, _radius, _flipDistance );
139 _mSrc.convertTo(srcMap, CV_8U);
141 int maskSize0 = CV_DIST_MASK_PRECISE;
142 int voronoiType = -1;
143 int distType0 = CV_DIST_L2;
144 int maskSize = voronoiType >= 0 ? CV_DIST_MASK_5 : maskSize0;
145 int distType = voronoiType >= 0 ? CV_DIST_L2 : distType0;
146 Mat destMap_f, labels;
148 if ( voronoiType < 0 ){ cv::distanceTransform ( srcMap, destMap_f, distType, maskSize ); }
149 else { cv::distanceTransform ( srcMap, destMap_f, labels, distType, maskSize, voronoiType ); }
152 CV_Assert(destMap_f.depth() == CV_32F);
153 int channels = destMap_f.channels();
154 int nRows = destMap_f.rows;
155 int nCols = destMap_f.cols * channels;
156 if (destMap_f.isContinuous()) { nCols *= nRows; nRows = 1; }
158 float threshold = _radius * scale_x ();
159 float_t* p_d;
float* p_s;
160 for(
int i = 0; i < nRows; ++i) {
161 p_d = destMap_f.ptr<float_t>(i);
165 if ( ( _mDst.channels() != 1 ) && ( _mDst.channels() != 5 ) ) {
cvtColor(destMap_f, _mDst, CV_GRAY2BGR ); }
166 else { _mDst = destMap_f; }
bool inside(double x0, double y0, double x1, double y1) const
void resizeLayers(const size_t &_n)
virtual void initLayers()
float distance2probabilitySigmoid(float d, float threshold)
void init(const M_string &remappings)
void computeDistanceField(cv::Mat &_mDst, std::vector< Point2D > &_pSrc, const double &_radius, bool _flipDistance=false, bool connectPoints=false) const
void clearLayer(const size_t &_layer)
float distance2probabilityTriangle(float d, float threshold)
cv::Mat & mapLayer(const size_t &_layer)
size_t sizeLayers() const
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
double getVal(const size_t &_layer, const tuw::Point2D &_worldPos, Interpolation interpolationType=BILINEAR) const