#include <stdio.h>
#include <unistd.h>
+#include <fstream>
namespace MediaVision {
namespace Face {
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<cv::FaceRecognizer>& srcAlg,
cv::Ptr<cv::FaceRecognizer>& 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);