Add the option to focus on a spcific person
This commit is contained in:
parent
f97f4640a9
commit
55953bcdb7
3 changed files with 27 additions and 12 deletions
|
|
@ -106,28 +106,35 @@ void FaceRecognizer::clearReferances()
|
|||
referanceFeatures.clear();
|
||||
}
|
||||
|
||||
std::pair<int, double> FaceRecognizer::isMatch(const cv::Mat& input, bool alone)
|
||||
FaceRecognizer::Detection FaceRecognizer::isMatch(const cv::Mat& input, bool alone)
|
||||
{
|
||||
cv::Mat faces = detectFaces(input);
|
||||
|
||||
if(alone && faces.rows > 1)
|
||||
return {-2, 0};
|
||||
Detection bestMatch;
|
||||
bestMatch.confidence = 0;
|
||||
bestMatch.person = -1;
|
||||
|
||||
std::pair<int, double> bestMatch = {-1, 0};
|
||||
if(alone && faces.rows > 1)
|
||||
{
|
||||
bestMatch.person = -2;
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
for(int i = 0; i < faces.rows; ++i)
|
||||
{
|
||||
cv::Mat face;
|
||||
recognizer->alignCrop(input, faces.row(0), face);
|
||||
recognizer->alignCrop(input, faces.row(i), face);
|
||||
cv::Mat features;
|
||||
recognizer->feature(face, features);
|
||||
features = features.clone();
|
||||
for(size_t referanceIndex = 0; referanceIndex < referanceFeatures.size(); ++referanceIndex)
|
||||
{
|
||||
double score = recognizer->match(referanceFeatures[referanceIndex], features, cv::FaceRecognizerSF::FR_COSINE);
|
||||
if(score > threshold && score > bestMatch.second)
|
||||
if(score > threshold && score > bestMatch.confidence)
|
||||
{
|
||||
bestMatch = {referanceIndex, score};
|
||||
bestMatch.confidence = score;
|
||||
bestMatch.person = referanceIndex;
|
||||
bestMatch.rect = cv::Rect(faces.at<int>(i, 0), faces.at<int>(i, 1), faces.at<int>(i, 2), faces.at<int>(i, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue