Hello,
I would like to follow [this tutorial](http://docs.opencv.org/2.4/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html) but in the read CSV function, I have a problem with imread. Normally, a Mat should be populate by thanks to imread function but it's empty for each read attempt. This is my code :
#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include
#include
using namespace cv;
using namespace std;
static void read_csv(const string& filename, vector& images, vector& labels, char separator = ';') {
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(CV_StsBadArg, error_message);
}
string line, path, classlabel;
int numberImageReaded = 0;
while (getline(file, line)) {
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if(!path.empty() && !classlabel.empty()) {
Mat m = imread(path, 1);
if (m.empty())
{
cerr << path << " could not be read." << endl;
continue;
}
Mat m2;
cout << endl << "New image read";
cvtColor(m,m2,CV_BGR2GRAY);
numberImageReaded++;
cout << endl << "Number of image read = " << numberImageReaded;
images.push_back(m2);
labels.push_back(atoi(classlabel.c_str()));
}
}
cout << endl << "Read finish";
}
int main() {
string fn_csv = string("data.csv");
vector images;
vector labels;
try {
read_csv(fn_csv, images, labels);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
exit(1);
}
return 0;
}
I read the [documentation](http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread) and for my case (Ubuntu 16.04), I should install libjpeg-de. I install it but it doesn't solve the problem. I need to add the flag OPENCV_BUILD_3RDPARTY_LIBS but I don't know where I should add it. I compile with this command :
> clang++ -std=c++11 main.cpp -o w> `pkg-config --cflags --libs opencv`
This is the result when I launch the program :
> user@user-PC:~/Bureau/readCSVopenCV$> ./w ��./S1/27.pngg could not be read.
> ./S1/12.pngg could not be read.> ./S1/9.pngg could not be read. ......> ...... ./S1/6.pngg could not be read.> ./S1/20.pngg could not be read. could> not be read. Read finish
↧