00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <rtabmap/core/clams/discrete_depth_distortion_model.h>
00031 #include <opencv2/imgproc/imgproc.hpp>
00032 #include <opencv2/highgui/highgui.hpp>
00033 #include <rtabmap/utilite/ULogger.h>
00034 #include <rtabmap/utilite/UDirectory.h>
00035
00036 using namespace std;
00037 using namespace Eigen;
00038
00039 namespace clams
00040 {
00041
00042 cv::Mat DiscreteDepthDistortionModel::visualize(const std::string& dir) const
00043 {
00044 bool writeFiles = !dir.empty() && UDirectory::exists(dir);
00045
00046 const DiscreteFrustum& reference_frustum = *frustums_[0][0];
00047 int num_layers = reference_frustum.num_bins_;
00048
00049
00050 int horiz_divider = 10;
00051 int vert_divider = 20;
00052 cv::Mat3b overview(cv::Size(width_ * 2 + horiz_divider, height_ * num_layers + vert_divider * (num_layers + 2)), cv::Vec3b(0, 0, 0));
00053 vector<int> pub_layers;
00054 for(int i = 0; i < num_layers; ++i)
00055 pub_layers.push_back(i);
00056
00057
00058
00059 cv::Mat3b pub(cv::Size(width_, height_ * pub_layers.size() + vert_divider * (pub_layers.size() + 2)), cv::Vec3b(255, 255, 255));
00060
00061 for(int i = 0; i < num_layers; ++i) {
00062
00063 char buffer[50];
00064 float mindepth = reference_frustum.bin_depth_ * i;
00065 float maxdepth = reference_frustum.bin_depth_ * (i + 1);
00066 sprintf(buffer, "%05.2f-%05.2f", mindepth, maxdepth);
00067 ostringstream oss;
00068 oss << dir << "/multipliers_" << buffer << ".png";
00069
00070
00071
00072 cv::Mat3b mult(cv::Size(width_, height_), cv::Vec3b(0, 0, 0));
00073 for(int y = 0; y < mult.rows; ++y) {
00074 for(int x = 0; x < mult.cols; ++x) {
00075 const DiscreteFrustum& frustum = *frustums_[y / bin_height_][x / bin_width_];
00076 float val = frustum.multipliers_(i);
00077 if(val > 1)
00078 mult(y, x)[2] = min(255., 255 * (val - 1.0) / 0.25);
00079 if(val < 1)
00080 mult(y, x)[0] = min(255., 255 * (1.0 - val) / 0.25);
00081 }
00082 }
00083 if(writeFiles)
00084 {
00085 cv::imwrite(oss.str(), mult);
00086 UINFO("Written \"%s\"", oss.str().c_str());
00087 }
00088
00089
00090
00091 cv::Mat3b count(cv::Size(width_, height_), cv::Vec3b(0, 0, 0));
00092 for(int y = 0; y < count.rows; ++y) {
00093 for(int x = 0; x < count.cols; ++x) {
00094 const DiscreteFrustum& frustum = *frustums_[y / bin_height_][x / bin_width_];
00095 uchar val = min(255., (double)(255 * frustum.counts_(i) / 100));
00096 count(y, x)[0] = val;
00097 count(y, x)[1] = val;
00098 count(y, x)[2] = val;
00099 }
00100 }
00101 oss.str("");
00102 oss << dir << "/counts_" << buffer << ".png";
00103 if(writeFiles)
00104 {
00105 cv::imwrite(oss.str(), count);
00106 UINFO("Written \"%s\"", oss.str().c_str());
00107 }
00108
00109
00110 cv::Mat3b combined(cv::Size(width_ * 2 + horiz_divider, height_), cv::Vec3b(0, 0, 0));
00111 for(int y = 0; y < combined.rows; ++y) {
00112 for(int x = 0; x < combined.cols; ++x) {
00113 if(x < count.cols)
00114 combined(y, x) = count(y, x);
00115 else if(x > count.cols + horiz_divider)
00116 combined(y, x) = mult(y, x - count.cols - horiz_divider);
00117 }
00118 }
00119 oss.str("");
00120 oss << dir << "/combined_" << buffer << ".png";
00121 if(writeFiles)
00122 {
00123 cv::imwrite(oss.str(), combined);
00124 UINFO("Written \"%s\"", oss.str().c_str());
00125 }
00126
00127
00128 for(int y = 0; y < combined.rows; ++y)
00129 for(int x = 0; x < combined.cols; ++x)
00130 overview(y + i * (combined.rows + vert_divider) + vert_divider, x) = combined(y, x);
00131
00132
00133
00134 cv::Mat3b pubmult(cv::Size(width_, height_), cv::Vec3b(255, 255, 255));
00135 for(int y = 0; y < pubmult.rows; ++y) {
00136 for(int x = 0; x < pubmult.cols; ++x) {
00137 const DiscreteFrustum& frustum = *frustums_[y / bin_height_][x / bin_width_];
00138 float val = frustum.multipliers_(i);
00139 if(val > 1) {
00140 pubmult(y, x)[0] = 255 - min(255., 255 * (val - 1.0) / 0.1);
00141 pubmult(y, x)[1] = 255 - min(255., 255 * (val - 1.0) / 0.1);
00142 }
00143 if(val < 1) {
00144 pubmult(y, x)[1] = 255 - min(255., 255 * (1.0 - val) / 0.1);
00145 pubmult(y, x)[2] = 255 - min(255., 255 * (1.0 - val) / 0.1);
00146 }
00147 }
00148 }
00149
00150
00151 for(size_t j = 0; j < pub_layers.size(); ++j)
00152 if(pub_layers[j] == i)
00153 for(int y = 0; y < pubmult.rows; ++y)
00154 for(int x = 0; x < pubmult.cols; ++x)
00155 pub(y + j * (pubmult.rows + vert_divider) + vert_divider, x) = pubmult(y, x);
00156 }
00157
00158
00159 for(int y = 0; y < overview.rows; ++y)
00160 if(y < vert_divider || y > overview.rows - vert_divider)
00161 for(int x = 0; x < overview.cols; ++x)
00162 overview(y, x) = cv::Vec3b(255, 255, 255);
00163
00164
00165 ostringstream oss;
00166 oss << dir << "/overview.png";
00167 if(writeFiles)
00168 {
00169 cv::imwrite(oss.str(), overview);
00170 UINFO("Written \"%s\"", oss.str().c_str());
00171 }
00172
00173
00174 cv::Mat3b overview_scaled;
00175 cv::resize(overview, overview_scaled, cv::Size(), 0.2, 0.2, cv::INTER_CUBIC);
00176 oss.str("");
00177 oss << dir << "/overview_scaled.png";
00178 if(writeFiles)
00179 {
00180 cv::imwrite(oss.str(), overview_scaled);
00181 UINFO("Written \"%s\"", oss.str().c_str());
00182 }
00183
00184
00185 oss.str("");
00186 oss << dir << "/pub";
00187
00188
00189 oss << ".png";
00190 if(writeFiles)
00191 {
00192 cv::imwrite(oss.str(), pub);
00193 UINFO("Written \"%s\"", oss.str().c_str());
00194 }
00195
00196 UASSERT(overview.rows == pub.rows);
00197 cv::Mat3b targetImage(overview.rows, overview.cols/2 + pub.cols);
00198
00199 cv::Mat roiA(targetImage, cv::Rect( 0, 0, overview.cols/2, overview.rows ));
00200 cv::Mat(overview, cv::Rect( 0, 0, overview.cols/2, overview.rows )).copyTo(roiA);
00201 cv::Mat roiB( targetImage, cv::Rect( overview.cols/2, 0, pub.cols, pub.rows ) );
00202 pub.copyTo(roiB);
00203
00204 return targetImage;
00205 }
00206
00207 }