FaceRecognitionConfig _config;
FaceRecognitionResult _result;
- // FYI. This function should be called every time a new face is registered.
- void importLabel();
void checkFeatureVectorFile(std::string fv_file_name, std::string new_fv_file_name);
void storeDataSet(std::unique_ptr<DataSetManager> &data_set, unsigned int label_cnt);
void checkResult();
return MEDIA_VISION_ERROR_NONE;
}
-void FaceRecognition::importLabel()
-{
- try {
- // Update label manager from a given label file.
- int cnt = _label_manager->importLabel();
-
- LOGD("%d labels have been imported", cnt);
- } catch (const BaseException &e) {
- LOGE("%s", e.what());
- throw e;
- }
-}
-
int FaceRecognition::registerNewFace(std::vector<float> &input_vec, string label_name)
{
if (_status < WorkingStatus::INITIALIZED) {
_label_manager->addLabelToFile(label_name);
// Import label data from a label file.
- importLabel();
+ _label_manager->importLabel();
// Get label index and count.
unsigned int label_idx = _label_manager->getLabelIndex(label_name);
try {
// Import label data from a label file.
- importLabel();
+ _label_manager->importLabel();
if (_label_manager->isEmpty()) {
_result.is_valid = false;
if (!FaceRecogUtil::isFileExist(_config.internal_model_file_path)) {
LOGE("Internal model file(%s) doesn't exist.", _config.internal_model_file_path.c_str());
- return MEDIA_VISION_ERROR_INVALID_PATH;
+ return MEDIA_VISION_ERROR_NO_DATA;
}
TrainingEngineBackendInfo engine_info = _training_model->getTrainingEngineInfo();
}
// Import label data from a label file.
- importLabel();
+ _label_manager->importLabel();
unsigned int target_label_idx = _label_manager->getLabelIndex(label_name);
auto label_cnt_ori = _label_manager->getMaxLabel();
float getDecisionWeight();
unsigned int getLabelIndex(const std::string &given_label);
bool isExist(const std::string given_label);
- unsigned int removeLabel(const std::string given_label);
+ void removeLabel(const std::string given_label);
void getLabelString(std::string &label, const int idx);
void addLabelToFile(std::string given_label);
- size_t importLabel(void);
+ void importLabel(void);
const std::vector<std::string> &getLabels(void);
size_t getMaxLabel();
void removeFile();
return distance(_labels.begin(), iter);
}
-unsigned int LabelManager::removeLabel(const string given_label)
+void LabelManager::removeLabel(const string given_label)
{
ifstream readFile { _label_file };
if (total_length == writeFile.tellp()) {
if (::remove(new_label_file.c_str()) == -1)
throw InvalidOperation("Fail to remove label file.");
-
- return _labels.size();
}
if (::remove(_label_file.c_str()) == -1)
if (::rename(new_label_file.c_str(), _label_file.c_str()) == -1)
throw InvalidOperation("Fail to rename new labal file to original one.");
- return importLabel(); // Update _labels because label file is changed.
+ // Update _labels because label file is changed.
+ importLabel();
}
void LabelManager::getLabelString(string &label, const int idx)
writeFile.close();
}
-size_t LabelManager::importLabel(void)
+void LabelManager::importLabel(void)
{
- // label count is 0 if label file doesn't exist.
- if (!FaceRecogUtil::isFileExist(_label_file)) {
- _labels.clear();
- return 0;
- }
+ // just return if label file doesn't exist.
+ if (!FaceRecogUtil::isFileExist(_label_file))
+ return;
ifstream readFile;
readFile.close();
- return _labels.size();
+ LOGD("%zu labels have been imported", _labels.size());
}
const std::vector<std::string> &LabelManager::getLabels(void)
bool LabelManager::isEmpty()
{
return _labels.empty();
-}
\ No newline at end of file
+}