From: Tae-Young Chung Date: Thu, 16 Jun 2022 05:19:11 +0000 (+0900) Subject: Change output type from 32float to unsigned 16bit integer X-Git-Tag: submit/tizen/20220701.002357~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c9bc2cf0a6c2c3fac0d9e481d5a0e5125206b9e;p=platform%2Fcore%2Fmultimedia%2Fdfs-opencv.git Change output type from 32float to unsigned 16bit integer The output is now real depth range, distance, not disparity. Signed-off-by: Tae-Young Chung --- diff --git a/packaging/dfs-opencv.spec b/packaging/dfs-opencv.spec index cc4594e..121f409 100644 --- a/packaging/dfs-opencv.spec +++ b/packaging/dfs-opencv.spec @@ -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 diff --git a/src/dfs_opencv.cpp b/src/dfs_opencv.cpp index b6b2faf..d72f0b2 100644 --- a/src/dfs_opencv.cpp +++ b/src/dfs_opencv.cpp @@ -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(fs["STEREO_DOFFSET"]); + LOGI("%f", mStereoParam.dispOffset); + } + + mDisp2DepthMat = cv::Mat(mImageSize, CV_32F, mStereoParam.baceCamera.intrinsic.at(0,0) * + mStereoParam.translation.at(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(); - 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(); + 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; diff --git a/src/dfs_opencv_private.h b/src/dfs_opencv_private.h index 3c3082f..e6da346 100644 --- a/src/dfs_opencv_private.h +++ b/src/dfs_opencv_private.h @@ -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;