问题描述
我曾经对C ++和Opencv 4.4.0算法进行一些修改以进行人脸识别...我使用的是Microsoft Visual Studio ...首先,该算法分两步执行人脸识别:第一个是ADDING_FACE()函数可在检测到对象的面部之后使用摄像头捕获帧,然后训练 EIGENFACETRAINER()函数,以便 FACE_RECOGNITION()函数可以使用此功能识别对象模型( eigenfacerecognizer )(步骤2)...这是原始代码的链接:https://github.com/ssj-ali/Face-Detection-Recognition ....
因此,我不想从网络摄像头获取帧,而是想使用已经存在许多引用许多主题的jpg图像的数据集,因此我尝试使用CSV文件,该文件在DATASET中保存了每个图像的路径(YALE FACE DATABASE B)和每个图像的标签,如下所示:
C:\yalefaces\TrainingSet\subject01happy.jpg;0
C:\yalefaces\TrainingSet\subject01leftlight.jpg;0
C:\yalefaces\TrainingSet\subject01noglasses.jpg;0
.
.
.
C:\yalefaces\TrainingSet\subject02happy.jpg;1
C:\yalefaces\TrainingSet\subject02leftlight.jpg;1
C:\yalefaces\TrainingSet\subject02noglasses.jpg;1
当我尝试将保存该csv文件路径的字符串传递给 read_CSV()函数时,出现一个错误,提示我提出了错误的论点....这是我在 FaceRec.h 文件
中所做的修改static void read_csv(const string& filename,vector<Mat>& images,vector<int>& labels,char separator = ';') {
cout << filename << endl;
std::ifstream file(filename.c_str(),ifstream::in);
if (!file) {
string error_message = "No valid input file was given,please check the given filename.";
CV_Error(Error::StsBadArg,error_message);
}
string line,path,classlabel;
while (getline(file,line)) {
stringstream liness(line);
getline(liness,separator);
getline(liness,classlabel);
if (!path.empty() && !classlabel.empty()) {
images.push_back(imread(path,0));
labels.push_back(atoi(classlabel.c_str()));
}
}
}
void addFace()
{
//cout << "\nEnter Your Name: ";
//cin >> name;
//VideoCapture capture(0);
// if (!capture.isOpened())
// return ;
//cout << "\nCapturing your face 10 times,Press 'C' 10 times keeping your face front of the camera";
// Get the path to your CSV.
string const fn_csv("E:\\CSV\\Sample.csv");
// These vectors hold the images and corresponding labels.
vector<Mat> images;
vector<int> labels;
// Read in the data. This can fail if no valid
// input filename is given.
try {
read_csv(fn_csv,images,labels);
}
catch (const cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
// nothing more we can do
exit(1);
}
// Quit if there are not enough images for this demo.
if (images.size() <= 1) {
string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!";
CV_Error(Error::StsError,error_message);
}
// Get the height from the first image. We'll need this
// later in code to reshape the images to their original
// size:
int height = images[0].rows;
.......
此open_vv库文档https://docs.opencv.org/master/da/d60/tutorial_face_main.html中已实现的read_csv()函数
所以我遇到了这个错误:
OpenCV(4.4.0-dev) Error: Bad argument (No valid input file was given,please check the given filename.) in read_csv,file c:\users\ayoub\music\face-detection-recognition-master\project1c++\facerec.h,line 52
Error opening file "E:\CSV\Sample.csv". Reason: OpenCV(4.4.0-dev) c:\users\ayoub\music\face-detection-recognition-master\project1c++\facerec.h:52: error: (-5:Bad argument) No valid input file was given,please check the given filename. in function 'read_csv'
您能帮我解决这个问题吗,我也想知道这种方法是否有用..否则,如果您可以建议我另一种方法进行修改,我将不胜感激
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)