From 8e1ad8aaffc338fb178ce5e32ed5ad66bb555d69 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Fri, 2 Dec 2016 15:39:59 +0900 Subject: [PATCH] Avoid throwing OpenCV's exception Change-Id: I3b5acaa4c8559e30a9775e56e819a0e5da4c0ab9 Signed-off-by: Tae-Young Chung --- mv_face/face/src/FaceRecognitionModel.cpp | 31 +++++++++++++++++++++++++++++-- packaging/capi-media-vision.spec | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mv_face/face/src/FaceRecognitionModel.cpp b/mv_face/face/src/FaceRecognitionModel.cpp index a0754a7..2b33312 100644 --- a/mv_face/face/src/FaceRecognitionModel.cpp +++ b/mv_face/face/src/FaceRecognitionModel.cpp @@ -23,6 +23,7 @@ #include #include +#include namespace MediaVision { namespace Face { @@ -31,15 +32,41 @@ namespace { unsigned int DefaultUnisizeWidth = 200; unsigned int DefaultUnisizeHeight = 200; +bool isEmptyAlgorithmParam(const std::string& path) +{ + char valid[256] = ""; + std::ifstream ifs; + + ifs.open(path.c_str()); + + if (!ifs.is_open()) { + LOGE("[%s] Can't open file.", path.c_str()); + return true; + } + + ifs.getline(valid, 256); + ifs.close(); + + LOGD("Validation string: %s", valid); + if (strlen(valid) <= 0) { + LOGE("algorithm params is empty."); + return true; + } + + return false; +} + int CopyOpenCVAlgorithmParameters(const cv::Ptr& srcAlg, cv::Ptr& dstAlg) { - char tempPath[1024]; + char tempPath[1024] = ""; snprintf(tempPath, 1024, "/tmp/alg_copy_%p_%p", srcAlg.obj, dstAlg.obj); srcAlg->save(tempPath); - dstAlg->load(tempPath); + + if (!isEmptyAlgorithmParam(tempPath)) + dstAlg->load(tempPath); if (0 != remove(tempPath)) LOGW("Error removing serialized FaceRecognizer in %s", tempPath); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 59c1217..2f44fe3 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.3.22 +Version: 0.3.23 Release: 1 Group: Multimedia/Framework License: Apache-2.0 and BSD-2.0 -- 2.7.4