Change output type from 32float to unsigned 16bit integer
authorTae-Young Chung <ty83.chung@samsung.com>
Thu, 16 Jun 2022 05:19:11 +0000 (14:19 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Thu, 16 Jun 2022 05:19:14 +0000 (14:19 +0900)
The output is now real depth range, distance, not disparity.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
packaging/dfs-opencv.spec
src/dfs_opencv.cpp
src/dfs_opencv_private.h

index cc4594ef403305a10eb2c666f5ec7de0b21a6302..121f409ac4a75b35547ee207b3912b3f1c573039 100644 (file)
@@ -1,6 +1,6 @@
 Name:       dfs-opencv
 Summary:    OpenCV based Depth-from-Stereo implementation
-Version:    1.0.4
+Version:    1.0.5
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index b6b2faf01e6135344f6a904b8004e77cdf679642..d72f0b2eb372280a05e392dd473a1c26cdb70f78 100644 (file)
@@ -36,6 +36,7 @@ namespace DfsAdaptationImpl
                mP2(96*1),
                mPreFilterCap(63),
                mDispMat(),
+               mDepthMat(),
                mDepthData(),
                mStereoParam(),
                mIsStereoCalibrated(false),
@@ -83,6 +84,15 @@ namespace DfsAdaptationImpl
                        fs["STEREO_TRANSLATION"] >> mStereoParam.translation;
                        fs["STEREO_ROTATION"] >> mStereoParam.rotation;
 
+                       if (!fs["STEREO_DOFFSET"].empty()) {
+                               mStereoParam.dispOffset = static_cast<float>(fs["STEREO_DOFFSET"]);
+                               LOGI("%f", mStereoParam.dispOffset);
+                       }
+
+                       mDisp2DepthMat = cv::Mat(mImageSize, CV_32F, mStereoParam.baceCamera.intrinsic.at<double>(0,0) *
+                                                                                                                mStereoParam.translation.at<double>(0));
+                       mDispOffsetMat = cv::Mat(mImageSize, CV_32F, mStereoParam.dispOffset);
+
                } catch (const std::exception& e) {
                        LOGE("Failed to read calibration data %s", e.what());
                        throw std::ios_base::failure("calibration");
@@ -449,11 +459,18 @@ namespace DfsAdaptationImpl
                        }
                }
 
-               mDepthData.data = mDispMat.ptr<float>();
-               mDepthData.type = DFS_DATA_TYPE_FLOAT32C1;
-               mDepthData.width = mDispMat.cols;
-               mDepthData.height = mDispMat.rows;
-               mDepthData.stride = mDispMat.elemSize() *  mDispMat.cols;
+               /* calculate real depth from instrinsic */
+               // mDisp2DeptMat = fx * baseline
+               // depth = fx * baseline / (disparity + offset)
+               // convert depth from 32F to 16U
+               cv::Mat deptF = mDisp2DepthMat.mul(1.0/(mDispMat + mDispOffsetMat));
+               deptF.convertTo(mDepthMat, CV_16U);
+
+               mDepthData.data = mDepthMat.ptr<unsigned short>();
+               mDepthData.type = DFS_DATA_TYPE_UINT16C1;
+               mDepthData.width = mDepthMat.cols;
+               mDepthData.height = mDepthMat.rows;
+               mDepthData.stride = mDepthMat.elemSize() *  mDepthMat.cols;
 
                mDepthData.pointCloudData = nullptr;
                mDepthData.pointCloudSize = 0;
index 3c3082f55ca95be695ef10060827e26ff0cbcec0..e6da346581b84ff91e4fbc2a3f4275eefb3b647a 100644 (file)
@@ -65,11 +65,13 @@ namespace DfsAdaptationImpl
 
                cv::Mat translation;
                cv::Mat rotation;
+               float dispOffset;
 
                _StereoParam()
                {
                        translation = cv::Mat(cv::Size(1,3), CV_32FC1);
                        rotation = cv::Mat(cv::Size(1,3), CV_32FC1);
+                       dispOffset = 0.f;
                }
        } StereoParam;
 
@@ -92,6 +94,9 @@ namespace DfsAdaptationImpl
 
 
                cv::Mat mDispMat;
+               cv::Mat mDepthMat;
+               cv::Mat mDisp2DepthMat;
+               cv::Mat mDispOffsetMat;
                DfsData mDepthData;
 
                StereoParam mStereoParam;