Ask Your Question

lukaszbobrek's profile - activity

2020-09-26 15:23:07 -0600 received badge  Notable Question (source)
2018-09-08 22:37:10 -0600 received badge  Popular Question (source)
2014-01-14 08:43:30 -0600 commented question Unsupported format or combination of formats while running face recognition from video.

Thanks a lot! Problem solved, I've got a couple of empty.png files which I had just for testing befor. So thanks to #berak I made step forward, but another problem occured. Now I am receiven "Segmentation fault" error. Any ideas?

2014-01-14 07:26:13 -0600 asked a question Unsupported format or combination of formats while running face recognition from video.

Each time I am trying to run programm I got this error. Can anyone help me with that? What may cause the issu?

OpenCV Error: Unsupported format or combination of formats (In the Fisherfaces method all input samples (training images) must be of equal size! Expected 76800 pixels, but was 0 pixels.) in train, file /hdd1/software/opencv/opencv-2.4.6.1/modules/contrib/src/facerec.cpp, line 455 terminate called after throwing an instance of 'cv::Exception' what(): /hdd1/software/opencv/opencv-2.4.6.1/modules/contrib/src/facerec.cpp:455: error: (-210) In the Fisherfaces method all input samples (training images) must be of equal size! Expected 76800 pixels, but was 0 pixels. in function train

And below is my source code:

>     #include "/usr/local/include/opencv2/core/core.hpp"
>     #include "/usr/local/include/opencv2/contrib/contrib.hpp"
>     #include "/usr/local/include/opencv2/highgui/highgui.hpp"
>     #include "/usr/local/include/opencv2/imgproc/imgproc.hpp"
>     #include "/usr/local/include/opencv2/objdetect/objdetect.hpp"
>     
>     #include <iostream>
>     #include <fstream>
>     #include <sstream>
>     #include <string>
>     
>     using namespace cv;
>     using namespace std;
>     
>     int WriteLabel(int prediction) {
>     ofstream label;
>     label.open("/home/lbobrek/public_html/FaceToLog/src/facerecognizer/label.txt");
>        if (label.fail())
>        {
>           return 1;
>        }
>     label << prediction;
>     label.close();
>     return 0;
>     }
>     
>     static void read_csv(const string& filename, vector<Mat>& images,
> vector<int>& 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;
>         while (getline(file, line)) {
>             stringstream liness(line);
>             getline(liness, path, separator);
>             getline(liness, classlabel);
>             if(!path.empty() && !classlabel.empty()) {
>                 images.push_back(imread(path, 0));
>                 labels.push_back(atoi(classlabel.c_str()));
>             }
>         }
>     }
>     
>     int main() {
>        //if (argc != 4) {
>        //     cout << "usage: " << argv[0] << " </path/to/haar_cascade>
> </path/to/csv.ext> </path/to/device
> id>" << endl;
>        //     cout << "\t </path/to/haar_cascade> -- Path to the
> Haar Cascade for face detection." <<
> endl;
>        //     cout << "\t </path/to/csv.ext> -- Path to the CSV
> file with the face database." << endl;
>        //     cout << "\t <device id> -- The webcam device id to grab frames from." << endl;
>        //     exit(1);
>        //}
>         // Get the path to your CSV:
>         remove("/home/lbobrek/public_html/FaceToLog/src/facerecognizer/label.txt");
>         string fn_haar = ("/home/lbobrek/public_html/FaceToLog/src/facerecognizer/haarcascade_frontalface_default.xml");
>         string fn_csv = ("/home/lbobrek/public_html/FaceToLog/src/database.csv");
>         string deviceId = ("/home/lbobrek/public_html/FaceToLog/src/video/login.webm");
>         // These vectors hold the images and corresponding labels:
>         vector<Mat> images;
>         vector<int> labels;
>         // Read in the data (fails if no valid input filename is given, but
> you'll get an error message):
>         try {
>             read_csv(fn_csv, images, labels);
>         } catch (cv::Exception& e) {
>             cerr << "Error opening file \"" << fn_csv << "\". Reason: "
> << e.msg << endl;
>             // nothing more we can do
>             exit(1);
>         }
>         int im_width = images[0].cols;
>         int im_height = images[0].rows;
>         // Create a FaceRecognizer and train it on the given images:
>         Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
>         model->train(images, labels);
>         CascadeClassifier haar_cascade;
>         haar_cascade.load(fn_haar);
>         // Get a handle to the Video device:
>         VideoCapture cap(deviceId);
>         // Check if we can use this device at all:
>         if(!cap.isOpened ...
(more)
2014-01-12 07:10:30 -0600 asked a question FaceRecognizer is there any way to use prediction with string format (instead of int).

Hello eveyone,

I would like to use receive string instead of int from prediction function.

my .csv file looks like that:

path/to/username1/username1-01.png;username1

path/to/username1/username1-02.png;username1

path/to/username2/username2-01.png;username2

path/to/username2/username2-02.png;username2

and so on

And I would like to get recognized label, for example username2 as variable, so I could write it to a text file. There is my code below, and I cannot use string format at the very bottom (string prediction = model->predict(face_resized);)

Can anyone help me with that?

> #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>
> 
> using namespace cv; using namespace
> std;
> 
> static void read_csv(const string&
> filename, vector<Mat>& images,
> vector<string>& 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;
>     while (getline(file, line)) {
>         stringstream liness(line);
>         getline(liness, path, separator);
>         getline(liness, classlabel);
>         if(!path.empty() && !classlabel.empty()) {
>             images.push_back(imread(path, 0));
>             labels.push_back((classlabel.c_str()));
>         }
>     } }
> 
> int main(int argc, const char *argv[])
> {     remove( "path_to_user.txt" );
> //change PATH!!!
>     if (argc != 4) {
>         cout << "usage: " << argv[0] << " </path/to/haar_cascade>
> </path/to/csv.ext> </path/to/device
> id>" << endl;
>         cout << "\t </path/to/haar_cascade> -- Path to the
> Haar Cascade for face detection." <<
> endl;
>         cout << "\t </path/to/csv.ext> -- Path to the CSV file with the face database." << endl;
>         cout << "\t <device id> -- The webcam device id to grab frames from."
> << endl;
>         exit(1);
>     }
>     // Get the path to your CSV:
>     string fn_haar = string(argv[1]);
>     string fn_csv = string(argv[2]);
>     string deviceId = string(argv[3]);
>     // These vectors hold the images and corresponding labels:
>     vector<Mat> images;
>     vector<string> labels;
>     // Read in the data (fails if no valid input filename is given, but
> you'll get an error message):
>     try {
>         read_csv(fn_csv, images, labels);
>     } catch (cv::Exception& e) {
>         cerr << "Error opening file \"" << fn_csv << "\". Reason: " <<
> e.msg << endl;
>         // nothing more we can do
>         exit(1);
>     }
>     // Get the height from the first image. We'll need this
>     // later in code to reshape the images to their original
>     // size AND we need to reshape incoming faces to this size:
>     int im_width = images[0].cols;
>     int im_height = images[0].rows;
>     // Create a FaceRecognizer and train it on the given images:
>     Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
>     model->train(images, labels);
>     // That's it for learning the Face Recognition model. You now
>     // need to create the classifier for the task of Face Detection.
>     // We are going to use the haar cascade you have specified in the
>     // command line arguments:
>     //
>     CascadeClassifier haar_cascade;
>     haar_cascade.load(fn_haar);
>     // Get a handle to the Video device:
>     VideoCapture cap(deviceId);
>     // Check if we can use this device at all:
>     if(!cap.isOpened()) {
>         cerr << "Capture Device ID " << deviceId << "cannot be opened." <<
> endl;
>         return -1;
>     }
>     // Holds the current frame from ...
(more)
2014-01-01 14:28:07 -0600 asked a question Using captured .avi file instaed of webcam

Hi there, I am trying to implement Face Recognition in Videos source code for my purpose (http://docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html), but as an input i need to use .avi file instead of webcam.

I will be delighted if anyone could help me.

Cheers, Lukasz