Apply changed DFS_DATA_TYPE_* enumeration and a case which a given source is single...
authorTae-Young Chung <ty83.chung@samsung.com>
Tue, 2 Nov 2021 09:01:08 +0000 (18:01 +0900)
committer엘무럿/선행S/W Lab(생활가전)/Principal Engineer/삼성전자 <e.talipov@samsung.com>
Tue, 14 Dec 2021 02:21:04 +0000 (11:21 +0900)
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
src/dfs_opencv.cpp

index 47d5dc054f453cf7c3955aae970a539da05a419b..93496cad77aaadf11a6796a83d0fcab90a8f9e8f 100644 (file)
@@ -233,7 +233,9 @@ namespace DfsAdaptationImpl
        {
                LOGI("LEAVE");
                switch (type) {
-               case DFS_DATA_TYPE_UINT8:
+               case DFS_DATA_TYPE_UINT8C1:
+                       return CV_8UC1;
+               case DFS_DATA_TYPE_UINT8C3:
                        return CV_8UC3;
                default:
                        LOGE("Invalide type");
@@ -309,23 +311,51 @@ namespace DfsAdaptationImpl
        {
                LOGI("ENTER");
 
-               if (!base.data || !extra.data) {
+               if (!base.data) {
                        throw std::runtime_error("invalid data pointer");
                }
 
-               if (cv::Size(base.width, base.height) != mImageSize ||
-                       cv::Size(extra.width, extra.height) != mImageSize) {
-                       throw std::runtime_error("invalid size");
-               }
+               int baseCvType = 1;
+               int extraCvType = -1;
+               cv::Mat baseMat, extraMat;
 
-               int baseCvType = ConvertDfsDataTypeToCV(base.type);
-               int extraCvType = ConvertDfsDataTypeToCV(extra.type);
-               if (baseCvType < 0 || extraCvType < 0) {
-                       throw std::runtime_error("invalid data type");
-               }
+               if (!extra.data) {
+                       LOGI("side-by-side");
+                       if (cv::Size(base.width >> 1, base.height) != mImageSize) {
+                               throw std::runtime_error("invalid size");
+                       }
 
-               cv::Mat baseMat(cv::Size(base.width, base.height), baseCvType, base.data);
-               cv::Mat extraMat(cv::Size(extra.width, extra.height), extraCvType, extra.data);
+                       baseCvType = ConvertDfsDataTypeToCV(base.type);
+                       if (baseCvType < 0) {
+                               throw std::runtime_error("invalid data type");
+                       }
+                       cv::Mat mat(cv::Size(base.width, base.height), baseCvType, base.data);
+                       LOGI("%zd x %zd", base.width, base.height);
+                       baseMat = mat(cv::Rect(0, 0,
+                                               mImageSize.width,
+                                               mImageSize.height)).clone();
+                       extraMat = mat(cv::Rect(mImageSize.width, 0,
+                                               mImageSize.width,
+                                               mImageSize.height)).clone();
+               } else {
+                       if (cv::Size(base.width, base.height) != mImageSize ||
+                               cv::Size(extra.width, extra.height) != mImageSize) {
+                               throw std::runtime_error("invalid size");
+                       }
+                       baseCvType = ConvertDfsDataTypeToCV(base.type);
+                       extraCvType = ConvertDfsDataTypeToCV(extra.type);
+                       if (baseCvType < 0 || extraCvType < 0) {
+                               throw std::runtime_error("invalid data type");
+                       }
+
+                       baseMat = cv::Mat(cv::Size(base.width, base.height),
+                                                       baseCvType,
+                                                       base.data);;
+                       extraMat = cv::Mat(cv::Size(extra.width,
+                                                       extra.height),
+                                                       extraCvType,
+                                                       extra.data);
+               }
 
                if (baseMat.size() != extraMat.size()) {
                        throw std::runtime_error("base and extra should be the same size");
@@ -415,7 +445,7 @@ namespace DfsAdaptationImpl
                }
 
                mDepthData.data = mDispMat.ptr<unsigned char>();
-               mDepthData.type = DFS_DATA_TYPE_UINT8;
+               mDepthData.type = DFS_DATA_TYPE_UINT8C1;
                mDepthData.width = mDispMat.cols;
                mDepthData.height = mDispMat.rows;
                mDepthData.stride = mDispMat.elemSize() *  mDispMat.cols;