Add stereoCalibZed.yaml for stereo calibration and add InitializeStereoCalibration...
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 18 Oct 2021 06:51:18 +0000 (15:51 +0900)
committer엘무럿/선행S/W Lab(생활가전)/Principal Engineer/삼성전자 <e.talipov@samsung.com>
Tue, 14 Dec 2021 02:21:04 +0000 (11:21 +0900)
The stereoCalibZed.yaml file is for zed camera only. It is added to test dfs-opencv using zed camera.
You should change the file if you try to use other camera.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
packaging/dfs-opencv.spec
res/stereoCalibZed.yaml [new file with mode: 0644]
src/dfs_opencv.cpp
src/dfs_opencv_private.h

index de5bfa15789c9363e148c4aa615930ecef7b9e56..7465b129b66ac31cf1910cfcc0dc51cf99101fb3 100644 (file)
@@ -11,6 +11,7 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(dfs-adaptation)
 BuildRequires: pkgconfig(opencv)
+BuildRequires: pkgconfig(libtzplatform-config)
 
 %description
 OpenCV based Dept-from-Stereo implementation
@@ -26,12 +27,16 @@ export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
 export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %endif
 
+export CXXFLAGS+=" -DDFS_CALIB_FILE_PATH=\\\"%{TZ_SYS_RO_SHARE}/%{name}/\\\""
+
 %cmake .
 
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
+mkdir -p %{buildroot}%{_datadir}/%{name}
+cp res/*.yaml %{buildroot}%{_datadir}/%{name}/
 
 %make_install
 
@@ -43,3 +48,4 @@ rm -rf %{buildroot}
 %license LICENSE.APLv2
 %defattr(-,root,root,-)
 %{_libdir}/*.so
+%{_datadir}/%{name}/*.yaml
diff --git a/res/stereoCalibZed.yaml b/res/stereoCalibZed.yaml
new file mode 100644 (file)
index 0000000..615f2bd
--- /dev/null
@@ -0,0 +1,31 @@
+%YAML:1.0
+LEFT_CAM_VGA: !!opencv-matrix
+    rows: 3
+    cols: 3
+    dt: d
+    data: [ 263.7425, 0., 333.64, 0., 263.5325, 184.129, 0., 0., 1. ]
+LEFT_CAM_DISTCOEFFS: !!opencv-matrix
+    rows: 5
+    cols: 1
+    dt: d
+    data: [ -0.0397725, 0.00826312, -0.00435501, -0.000558719, 0.000138723 ]
+RIGHT_CAM_VGA: !!opencv-matrix
+    rows: 3
+    cols: 3
+    dt: d
+    data: [ 264.02, 0., 335.0625, 0., 263.8875, 182.037, 0., 0., 1. ]
+RIGHT_CAM_DISTCOEFFS: !!opencv-matrix
+    rows: 5
+    cols: 1
+    dt: d
+    data: [ -0.0416412, 0.00967152, -0.00473998, 0.000477674, 0.00033336 ]
+STEREO_TRANSLATION: !!opencv-matrix
+    rows: 3
+    cols: 1
+    dt: d
+    data: [ 119.814, -0.0286845, 0.0224355 ]
+STEREO_ROTATION: !!opencv-matrix
+    rows: 3
+    cols: 1
+    dt: d
+    data: [ 0.0017263, 0.00115139, -0.000467542 ]
\ No newline at end of file
index 98f727885d2c3fd2c009c1d81c985be58cb13afe..ccde94ebc78ed5e3b4f2c016533ffc3f1337e453 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "dfs_opencv_private.h"
 #include <dlog.h>
+#include <opencv2/core/persistence.hpp>
+
+#define DEFAULT_STEREO_CALIB_FILE_NAME "stereoCalibZed.yaml"
 
 namespace DfsAdaptationImpl
 {
@@ -29,9 +32,14 @@ namespace DfsAdaptationImpl
                mP2(96*3),
                mPreFilterCap(63),
                mDispMat(),
-               mDepthData()
+               mDepthData(),
+               mCalibFilePath(DFS_CALIB_FILE_PATH),
+               mStereoParam(),
+               mIsStereoCalibrated(false),
+               mUpdateStereoCalibration(false)
        {
                LOGI("ENTER");
+               mCalibFilePath += std::string(DEFAULT_STEREO_CALIB_FILE_NAME);
                LOGI("LEAVE");
        }
 
@@ -41,6 +49,37 @@ namespace DfsAdaptationImpl
                LOGI("LEAVE");
        }
 
+       void DfsOCV::InitializeStereoCalibration()
+       {
+               LOGI("ENTER");
+
+               cv::Mat intrinsicTest;
+               try {
+                       cv::FileStorage fs(mCalibFilePath, cv::FileStorage::READ);
+                       if (!fs.isOpened()) {
+                               LOGE("Failed to open calib file %s", mCalibFilePath.c_str());
+                               throw std::ios_base::failure("calibration");
+                       }
+
+                       fs["LEFT_CAM_VGA"] >> mStereoParam.baceCamera.intrinsic;
+                       fs["LEFT_CAM_DISTCOEFFS"] >> mStereoParam.baceCamera.distCoeffs;
+
+                       fs["RIGHT_CAM_VGA"] >> mStereoParam.extraCamera.intrinsic;
+                       fs["RIGHT_CAM_DISTCOEFFS"] >> mStereoParam.extraCamera.distCoeffs;
+
+                       fs["STEREO_TRANSLATION"] >> mStereoParam.translation;
+                       fs["STEREO_ROTATION"] >> mStereoParam.rotation;
+
+                       mIsStereoCalibrated = true;
+
+               } catch (const std::exception& e) {
+                       LOGE("Failed to read calibration data %s", e.what());
+                       throw std::ios_base::failure("calibration");
+               }
+
+               LOGI("LEAVE");
+       }
+
        void DfsOCV::Initialize(DfsParameter& param)
        {
                LOGI("ENTER");
@@ -50,6 +89,13 @@ namespace DfsAdaptationImpl
                mDfsOcv = cv::StereoSGBM::create(1, mNumDisparities, mBlockSize);
 
                this->SetParameters();
+
+               try {
+                       this->InitializeStereoCalibration();
+               } catch (const std::exception& e) {
+                       throw e;
+               }
+
                LOGI("LEAVE");
        }
 
index fba50456c7b43fbb28c72de4d14cc06c125ff44a..e52d221694670215dd3d203b1718bf77e06bcfa0 100644 (file)
@@ -40,6 +40,31 @@ using namespace DfsAdaptation;
 
 namespace DfsAdaptationImpl
 {
+       typedef struct _CameraParam {
+               cv::Mat intrinsic;
+               cv::Mat distCoeffs;
+
+               _CameraParam()
+               {
+                       intrinsic = cv::Mat(cv::Size(3,3), CV_32FC1);
+                       distCoeffs = cv::Mat(cv::Size(1,5), CV_32FC1);
+               }
+       } CameraParam;
+
+       typedef struct _StereoParam {
+               CameraParam baceCamera;
+               CameraParam extraCamera;
+
+               cv::Mat translation;
+               cv::Mat rotation;
+
+               _StereoParam()
+               {
+                       translation = cv::Mat(cv::Size(1,3), CV_32FC1);
+                       rotation = cv::Mat(cv::Size(1,3), CV_32FC1);
+               }
+       } StereoParam;
+
        class DfsOCV : public IDfsAdaptation
        {
        private:
@@ -56,8 +81,14 @@ namespace DfsAdaptationImpl
                cv::Mat mDispMat;
                DfsData mDepthData;
 
+               std::string mCalibFilePath;
+               StereoParam mStereoParam;
+               bool mIsStereoCalibrated;
+               bool mUpdateStereoCalibration;
+
                void SetParameters();
                int  ConvertDfsDataTypeToCV(int type);
+               void InitializeStereoCalibration();
        public:
                DfsOCV();
                ~DfsOCV();