Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project-sd-card by
facerec.cpp
00001 /* 00002 * Copyright (c) 2011,2012. Philipp Wagner <bytefish[at]gmx[dot]de>. 00003 * Released to public domain under terms of the BSD Simplified license. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of the organization nor the names of its contributors 00013 * may be used to endorse or promote products derived from this software 00014 * without specific prior written permission. 00015 * 00016 * See <http://www.opensource.org/licenses/bsd-license> 00017 */ 00018 #include "precomp.hpp" 00019 #include "opencv2/face.hpp" 00020 00021 namespace cv 00022 { 00023 namespace face 00024 { 00025 00026 std::vector<int> FaceRecognizer::getLabelsByString(const String &str) const 00027 { 00028 std::vector<int> labels; 00029 for (std::map<int, String>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) 00030 { 00031 size_t found = (it->second).find(str); 00032 if (found != String::npos) 00033 labels.push_back(it->first); 00034 } 00035 return labels; 00036 } 00037 00038 String FaceRecognizer::getLabelInfo(int label) const 00039 { 00040 std::map<int, String>::const_iterator iter(_labelsInfo.find(label)); 00041 return iter != _labelsInfo.end() ? iter->second : ""; 00042 } 00043 00044 void FaceRecognizer::setLabelInfo(int label, const String &strInfo) 00045 { 00046 _labelsInfo[label] = strInfo; 00047 } 00048 00049 void FaceRecognizer::update(InputArrayOfArrays src, InputArray labels) 00050 { 00051 (void)src; 00052 (void)labels; 00053 String error_msg = format("This FaceRecognizer does not support updating, you have to use FaceRecognizer::train to update it."); 00054 CV_Error(Error::StsNotImplemented, error_msg); 00055 } 00056 00057 void FaceRecognizer::load(const String &filename) 00058 { 00059 FileStorage fs(filename, FileStorage::READ); 00060 if (!fs.isOpened()) 00061 CV_Error(Error::StsError, "File can't be opened for reading!"); 00062 this->load(fs); 00063 fs.release(); 00064 } 00065 00066 void FaceRecognizer::save(const String &filename) const 00067 { 00068 FileStorage fs(filename, FileStorage::WRITE); 00069 if (!fs.isOpened()) 00070 CV_Error(Error::StsError, "File can't be opened for writing!"); 00071 this->save(fs); 00072 fs.release(); 00073 } 00074 00075 int FaceRecognizer::predict(InputArray src) const { 00076 int _label; 00077 double _dist; 00078 predict(src, _label, _dist); 00079 return _label; 00080 } 00081 00082 void FaceRecognizer::predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const { 00083 Ptr<StandardCollector> collector = StandardCollector::create(getThreshold()); 00084 predict(src, collector); 00085 label = collector->getMinLabel(); 00086 confidence = collector->getMinDist(); 00087 } 00088 00089 } 00090 } 00091 00092
Generated on Tue Jul 12 2022 14:46:35 by
