31 #include <opencv2/imgproc/imgproc.hpp> 32 #include <opencv2/highgui/highgui.hpp> 37 using namespace Eigen;
42 cv::Mat DiscreteDepthDistortionModel::visualize(
const std::string& dir)
const 47 int num_layers = reference_frustum.
num_bins_;
50 int horiz_divider = 10;
51 int vert_divider = 20;
52 cv::Mat3b overview(cv::Size(width_ * 2 + horiz_divider, height_ * num_layers + vert_divider * (num_layers + 2)), cv::Vec3b(0, 0, 0));
53 vector<int> pub_layers;
54 for(
int i = 0; i < num_layers; ++i)
55 pub_layers.push_back(i);
59 cv::Mat3b pub(cv::Size(width_, height_ * pub_layers.size() + vert_divider * (pub_layers.size() + 2)), cv::Vec3b(255, 255, 255));
61 for(
int i = 0; i < num_layers; ++i) {
64 float mindepth = reference_frustum.
bin_depth_ * i;
65 float maxdepth = reference_frustum.
bin_depth_ * (i + 1);
66 sprintf(buffer,
"%05.2f-%05.2f", mindepth, maxdepth);
68 oss << dir <<
"/multipliers_" << buffer <<
".png";
72 cv::Mat3b mult(cv::Size(width_, height_), cv::Vec3b(0, 0, 0));
73 for(
int y = 0; y < mult.rows; ++y) {
74 for(
int x = 0; x < mult.cols; ++x) {
78 mult(y, x)[2] =
min(255., 255 * (val - 1.0) / 0.25);
80 mult(y, x)[0] =
min(255., 255 * (1.0 - val) / 0.25);
85 cv::imwrite(oss.str(), mult);
86 UINFO(
"Written \"%s\"", oss.str().c_str());
91 cv::Mat3b count(cv::Size(width_, height_), cv::Vec3b(0, 0, 0));
92 for(
int y = 0; y < count.rows; ++y) {
93 for(
int x = 0; x < count.cols; ++x) {
102 oss << dir <<
"/counts_" << buffer <<
".png";
105 cv::imwrite(oss.str(), count);
106 UINFO(
"Written \"%s\"", oss.str().c_str());
110 cv::Mat3b combined(cv::Size(width_ * 2 + horiz_divider, height_), cv::Vec3b(0, 0, 0));
111 for(
int y = 0; y < combined.rows; ++y) {
112 for(
int x = 0; x < combined.cols; ++x) {
114 combined(y, x) = count(y, x);
115 else if(x > count.cols + horiz_divider)
116 combined(y, x) = mult(y, x - count.cols - horiz_divider);
120 oss << dir <<
"/combined_" << buffer <<
".png";
123 cv::imwrite(oss.str(), combined);
124 UINFO(
"Written \"%s\"", oss.str().c_str());
128 for(
int y = 0; y < combined.rows; ++y)
129 for(
int x = 0; x < combined.cols; ++x)
130 overview(y + i * (combined.rows + vert_divider) + vert_divider, x) = combined(y, x);
134 cv::Mat3b pubmult(cv::Size(width_, height_), cv::Vec3b(255, 255, 255));
135 for(
int y = 0; y < pubmult.rows; ++y) {
136 for(
int x = 0; x < pubmult.cols; ++x) {
140 pubmult(y, x)[0] = 255 -
min(255., 255 * (val - 1.0) / 0.1);
141 pubmult(y, x)[1] = 255 -
min(255., 255 * (val - 1.0) / 0.1);
144 pubmult(y, x)[1] = 255 -
min(255., 255 * (1.0 - val) / 0.1);
145 pubmult(y, x)[2] = 255 -
min(255., 255 * (1.0 - val) / 0.1);
151 for(
size_t j = 0; j < pub_layers.size(); ++j)
152 if(pub_layers[j] == i)
153 for(
int y = 0; y < pubmult.rows; ++y)
154 for(
int x = 0; x < pubmult.cols; ++x)
155 pub(y + j * (pubmult.rows + vert_divider) + vert_divider, x) = pubmult(y, x);
159 for(
int y = 0; y < overview.rows; ++y)
160 if(y < vert_divider || y > overview.rows - vert_divider)
161 for(
int x = 0; x < overview.cols; ++x)
162 overview(y, x) = cv::Vec3b(255, 255, 255);
166 oss << dir <<
"/overview.png";
169 cv::imwrite(oss.str(), overview);
170 UINFO(
"Written \"%s\"", oss.str().c_str());
174 cv::Mat3b overview_scaled;
175 cv::resize(overview, overview_scaled, cv::Size(), 0.2, 0.2, cv::INTER_CUBIC);
177 oss << dir <<
"/overview_scaled.png";
180 cv::imwrite(oss.str(), overview_scaled);
181 UINFO(
"Written \"%s\"", oss.str().c_str());
186 oss << dir <<
"/pub";
192 cv::imwrite(oss.str(), pub);
193 UINFO(
"Written \"%s\"", oss.str().c_str());
196 UASSERT(overview.rows == pub.rows);
197 cv::Mat3b targetImage(overview.rows, overview.cols/2 + pub.cols);
199 cv::Mat roiA(targetImage, cv::Rect( 0, 0, overview.cols/2, overview.rows ));
200 cv::Mat(overview, cv::Rect( 0, 0, overview.cols/2, overview.rows )).copyTo(roiA);
201 cv::Mat roiB( targetImage, cv::Rect( overview.cols/2, 0, pub.cols, pub.rows ) );
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
Eigen::VectorXf multipliers_
#define UASSERT(condition)
ULogger class and convenient macros.
static bool exists(const std::string &dirPath)