J'ai un ensemble de données composé de 2 personnes (PERSON A
et PERSON B
).Reconnaissance de visage avec FisherFace toujours prédire une personne.Comment retourner -1 (personne inconnue) quand ne pas avoir formé la personne à faire face à l'appareil photo?
Mon code fonctionne parfaitement lorsque PERSON A
ou PERSON B
vont à la caméra (temps réel). Mais je tester à nouveau avec PERSON C
(ne pas avoir des images de formation de PERSON C
dans le fichier .csv) lorsque PERSON C
va à l'appareil photo; programme prévoit à nouveau A
ou B
.
Je veux retourner -1 (personne inconnue). Comment faire ça? J'utilise ce code;
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
using namespace cv;
using namespace std;
string person_name_1, person_name_2;
string haar_cascade_file = "C:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml";
CascadeClassifier detectFace;
string filename;
int filenumber;
VideoCapture video;
static void csvFile_read(const string& filename, vector<Mat>& images, vector<int>& labels, char seperator = ';'){
std::ifstream file(filename.c_str(), ifstream::in);
if (!file){
string error_message = "File not found";
CV_Error(CV_StsBadArg, error_message);
}
string line, file_path, file_label;
while (getline(file, line)){
stringstream lines(line);
getline(lines, file_path, seperator);
getline(lines, file_label);
if (!file_path.empty() && !file_label.empty()){
images.push_back(imread(file_path, 0));
labels.push_back(atoi(file_label.c_str()));
}
}
}
int main(int argc, const char *argv[]){
double const threshold = DBL_MAX;
string csv_file = "C:\\Users\\user\\Desktop\\Tutorialss\\important books\\final year\\DetectsAndRecognizeFaces\\DetectsAndRecognizeFaces\\DetectsAndRecognizeFaces\\csv.ext";
int cameraNo = 0;
vector<Mat> images;
vector<int> labels;
try{
csvFile_read(csv_file, images, labels);
}
catch (cv::Exception& e){
cerr << "Error " << csv_file << "\..." << " Reason: " << e.msg << endl;
exit(1);
}
int image_width = images[0].cols;
int image_height = images[0].rows;
Ptr<FaceRecognizer> face_recog_model = createFisherFaceRecognizer(0,DBL_MAX);
face_recog_model->train(images, labels);
detectFace.load(haar_cascade_file);
VideoCapture video(cameraNo);
if (!video.isOpened()){
cerr << cameraNo << " camera error" << endl;
return -1;
}
string person_list[] =
{
"PERSON A",
"PERSON B"
};
Mat live_video;
while (1){
video >> live_video;
Mat original = live_video.clone();
Mat grey;
cvtColor(original,grey, CV_BGR2GRAY);
vector< Rect_<int> > faces;
detectFace.detectMultiScale(grey, faces);
for (int i = 0; i < faces.size(); i++){
Rect face_i = faces[i];
Mat face = grey(face_i);
Mat face_resize;
resize(face, face_resize, Size(image_width, image_height), 1.0, 1.0, INTER_CUBIC);
int predict = face_recog_model->predict(face_resize);
rectangle(original, face_i, CV_RGB(0, 255, 0), 1);
string text_box;
text_box = format("Predict= ");
if (predict >= 0 && predict <= 1){
text_box.append(person_list[predict]);
}
else{
text_box.append("Unknown...");
}
int horizontal = std::max(face_i.tl().x - 10, 0);
int vertical = std::max(face_i.tl().y - 10, 0);
putText(original, text_box, Point(horizontal, vertical), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 255, 0), 2.0);
}
imshow("Face Detector", original);
char key = (char)waitKey(20);
if (key == 27)
break;
}
return 0;
}
et mon fichier csv:
path\personA_01.jpg;0
path\personA_02.jpg;0
path\personA_03.jpg;0
path\personA_04.jpg;0
path\personA_05.jpg;0
path\personA_06.jpg;0
path\personA_07.jpg;0
path\personA_08.jpg;0
path\personA_09.jpg;0
path\personA_10.jpg;0
path\personB_01.jpg;1
path\personB_02.jpg;1
path\personB_03.jpg;1
path\personB_04.jpg;1
path\personB_05.jpg;1
path\personB_06.jpg;1
path\personB_07.jpg;1
path\personB_08.jpg;1
path\personB_09.jpg;1
path\personB_10.jpg;1
Comment résoudre ce problème?
Je l'ai compris avant. Le programme retourne toujours -1 lorsque je définis la valeur de seuil sur "DBL_MIN" .Comment trouver la meilleure valeur de seuil pour mon système de reconnaissance faciale? –
Comme indiqué, je ne sais pas ce que DBL_MIN est. C'est probablement mieux si vous le comprenez d'abord. – poonam