Skip to content

Commit

Permalink
tested depth estimation node
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzoli committed Oct 29, 2015
1 parent 4168d27 commit c1b8f78
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 2 additions & 0 deletions include/rmd/depthmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Depthmap
void outputDepthmap(cv::Mat &depth_32fc1) const;
void outputDenoisedDepthmap(cv::Mat &depth_32fc1, float lambda, int iterations);

static cv::Mat scaleMat(const cv::Mat &depthmap);

private:
void inputImage(const cv::Mat &img_8uc1);

Expand Down
13 changes: 13 additions & 0 deletions src/depthmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ void rmd::Depthmap::outputDenoisedDepthmap(cv::Mat &depth_32fc1, float lambda, i
lambda,
iterations);
}

cv::Mat rmd::Depthmap::scaleMat(const cv::Mat &depthmap)
{
cv::Mat scaled_depthmap = depthmap.clone();
double min_val, max_val;
cv::minMaxLoc(scaled_depthmap, &min_val, &max_val);
cv::Mat converted;
scaled_depthmap = (scaled_depthmap - min_val) * 1.0 / (max_val - min_val);
scaled_depthmap.convertTo(converted, CV_8UC1, 255);
cv::Mat colored(converted.rows, converted.cols, CV_8UC3);
cv::cvtColor(converted, colored, CV_GRAY2BGR);
return colored;
}
12 changes: 11 additions & 1 deletion src/depthmap_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void rmd::DepthmapNode::denseInputCallback(

switch (state_) {
case rmd::State::TAKE_REFERENCE_FRAME:
{
if(depthmap_.setReferenceImage(
img_8uC1,
T_world_curr.inv(),
Expand All @@ -73,9 +74,18 @@ void rmd::DepthmapNode::denseInputCallback(
std::cerr << "ERROR: could not set reference image" << std::endl;
}
break;
}
case rmd::State::UPDATE:
depthmap_.update(img_8uC1, T_world_curr.inv());
{
depthmap_.update(img_8uC1, T_world_curr.inv());
#if 1
cv::Mat curr_depth;
depthmap_.outputDepthmap(curr_depth);
cv::imshow("curr_depth", rmd::Depthmap::scaleMat(curr_depth));
cv::waitKey(2);
#endif
break;
}
default:
break;
}
Expand Down
13 changes: 0 additions & 13 deletions test/dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,6 @@ const rmd::test::DatasetEntry & rmd::test::Dataset::operator()(size_t index) con
return dataset_.at(index);
}

cv::Mat rmd::test::Dataset::scaleMat(const cv::Mat &depthmap)
{
cv::Mat scaled_depthmap = depthmap.clone();
double min_val, max_val;
cv::minMaxLoc(scaled_depthmap, &min_val, &max_val);
cv::Mat converted;
scaled_depthmap = (scaled_depthmap - min_val) * 1.0 / (max_val - min_val);
scaled_depthmap.convertTo(converted, CV_8UC1, 255);
cv::Mat colored(converted.rows, converted.cols, CV_8UC3);
cv::cvtColor(converted, colored, CV_GRAY2BGR);
return colored;
}

bool rmd::test::Dataset::loadPathFromEnv()
{
const char *env_path = std::getenv(data_path_env_var);
Expand Down
1 change: 0 additions & 1 deletion test/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class Dataset
std::vector<DatasetEntry>::const_iterator end() const;
const DatasetEntry & operator()(size_t index) const;

static cv::Mat scaleMat(const cv::Mat &depthmap);
bool loadPathFromEnv();
static const char * getDataPathEnvVar();

Expand Down
4 changes: 2 additions & 2 deletions test/dataset_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ int main(int argc, char **argv)
// show depthmap
cv::Mat result;
depthmap.outputDepthmap(result);
cv::Mat colored = rmd::test::Dataset::scaleMat(result);
cv::Mat colored = rmd::Depthmap::scaleMat(result);
cv::imshow("result", colored);

// denoise
cv::Mat denoised_result;
depthmap.outputDenoisedDepthmap(denoised_result, 0.4f, 200);
cv::Mat colored_denoised = rmd::test::Dataset::scaleMat(denoised_result);
cv::Mat colored_denoised = rmd::Depthmap::scaleMat(denoised_result);
cv::imshow("denoised_result", colored_denoised);

cv::waitKey();
Expand Down

0 comments on commit c1b8f78

Please sign in to comment.