From d225b5ab5dc04a441212d7145bea7e2f0e0b97b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Laszkowski?= Date: Tue, 2 Sep 2014 17:40:45 +0200 Subject: [PATCH 1/2] DepthConverter INVALID_POINT fix --- .../DepthConverter/DepthConverter.cpp | 23 ++++++++++++------- .../DepthConverter/DepthConverter.hpp | 5 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Components/DepthConverter/DepthConverter.cpp b/src/Components/DepthConverter/DepthConverter.cpp index 1ad6e34..44d655b 100644 --- a/src/Components/DepthConverter/DepthConverter.cpp +++ b/src/Components/DepthConverter/DepthConverter.cpp @@ -15,13 +15,13 @@ namespace DepthConverter { DepthConverter::DepthConverter(const std::string & name) : Base::Component(name), depthMode("depth_mode",rawMap, "combo") { - LOG(LTRACE) << "Hello DepthConverter\n"; + CLOG(LTRACE) << "Hello DepthConverter"; registerProperty(depthMode); } DepthConverter::~DepthConverter() { - LOG(LTRACE) << "Good bye DepthConverter\n"; + CLOG(LTRACE) << "Good bye DepthConverter"; } void DepthConverter::prepareInterface() { @@ -40,20 +40,20 @@ void DepthConverter::prepareInterface() { } bool DepthConverter::onInit() { - LOG(LTRACE) << "DepthConverter::initialize\n"; + CLOG(LTRACE) << "DepthConverter::initialize"; return true; } bool DepthConverter::onFinish() { - LOG(LTRACE) << "DepthConverter::finish\n"; + CLOG(LTRACE) << "DepthConverter::finish"; return true; } bool DepthConverter::onStep() { - LOG(LTRACE) << "DepthConverter::step\n"; + CLOG(LTRACE) << "DepthConverter::step"; return true; } @@ -66,6 +66,7 @@ bool DepthConverter::onStart() { } void DepthConverter::onNewDepth() { + CLOG(LTRACE) << "DepthConverter::onNewDepth()"; m_depth = in_depth.read(); switch(depthMode) { @@ -99,6 +100,7 @@ void DepthConverter::onNewDepth() { * Based on OpenCv HighGUI */ void DepthConverter::convertToPointCloudMap(cv::Mat& data, cv::Mat& dataOut) { + CLOG(LTRACE) << "DepthConverter::convertToPointCloudMap()"; // !! This data are not exactly the same as when using opencv. Might need // some adjustments in the future. It's supposed to imitate the function // xnConvertProjectiveToRealWorld from OpenNI. Some attempt for this @@ -115,11 +117,11 @@ void DepthConverter::convertToPointCloudMap(cv::Mat& data, cv::Mat& dataOut) { cv::Mat pointCloud_XYZ(ROWS, COLS, CV_32FC3, cv::Scalar::all (INVALID_PIXEL)); - for (int y = 0; y < ROWS; y++) { for (int x = 0; x < COLS; x++) { double depth = data.at(y, x); // Check for invalid measurements + cout< (y, x) = cv::Point3f( INVALID_COORDINATE, INVALID_COORDINATE, @@ -128,10 +130,11 @@ void DepthConverter::convertToPointCloudMap(cv::Mat& data, cv::Mat& dataOut) { float xx = ((x - cx_d) * depth * fx_d) * 0.001f; float yy = ((y - cy_d) * depth * fy_d) * 0.001f; float dd = depth * 0.001f; - float zz = sqrt(dd*dd-xx*xx-yy*yy); + //float zz = sqrt(dd*dd-xx*xx-yy*yy); pointCloud_XYZ.at < cv::Point3f > (y, x) = cv::Point3f(xx, yy, dd); } } + cout<(y, x) = col; } } diff --git a/src/Components/DepthConverter/DepthConverter.hpp b/src/Components/DepthConverter/DepthConverter.hpp index 578e9ed..d81ac18 100644 --- a/src/Components/DepthConverter/DepthConverter.hpp +++ b/src/Components/DepthConverter/DepthConverter.hpp @@ -89,8 +89,9 @@ class DepthConverter: public Base::Component // "When the Kinect can't see the ir reflection // or has no depth data for a pixel, it returns // 2047 for the depth value" - static const int INVALID_PIXEL = 2047; - static const int INVALID_COORDINATE = 100000; + // 02.09.2014 FIX: according to the LibFreeNect documentation 0 is the value returned in the case of invalid depth. + static const int INVALID_PIXEL = 0; + static const int INVALID_COORDINATE = 100000; // baseline and focal length from opencv properties static const int BASELINE = 75; static const int FOCAL_LENGTH = 575; From 3674ab1b41225ba33728a5cc8e80f87c713f0c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Laszkowski?= Date: Tue, 2 Sep 2014 18:42:42 +0200 Subject: [PATCH 2/2] fix --- src/Components/DepthConverter/DepthConverter.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Components/DepthConverter/DepthConverter.cpp b/src/Components/DepthConverter/DepthConverter.cpp index 44d655b..ff20925 100644 --- a/src/Components/DepthConverter/DepthConverter.cpp +++ b/src/Components/DepthConverter/DepthConverter.cpp @@ -121,7 +121,6 @@ void DepthConverter::convertToPointCloudMap(cv::Mat& data, cv::Mat& dataOut) { for (int x = 0; x < COLS; x++) { double depth = data.at(y, x); // Check for invalid measurements - cout< (y, x) = cv::Point3f( INVALID_COORDINATE, INVALID_COORDINATE, @@ -134,7 +133,6 @@ void DepthConverter::convertToPointCloudMap(cv::Mat& data, cv::Mat& dataOut) { pointCloud_XYZ.at < cv::Point3f > (y, x) = cv::Point3f(xx, yy, dd); } } - cout<