Ask Your Question
0

Error in fisher faces algorithm when using multiple images for a person

asked 2017-10-30 02:24:45 -0600

Hi,

I'm using fisher faces algorithm and it's working fine when I use one image per person (label). once I'm adding two or more images for the same label I get this error (in the train method): Assertion failed (0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols) in cv::Mat::Mat

when I use one label with multiple images it works fine but if I use few labels and one of them has multiple images it failed with this error. I'm using the same pictures size for all of the pictures.

edit retag flag offensive close merge delete

Comments

hi, @namlool, good, you made it here.

again, the assertion is thrown because of an invalid (or empty) image region. please check all imread(), resize() calls, if there's facedetection involved, check, if the rects are all inside the image, and show the resp. code around those. there's for sure something wrong in your code, or the way, you handle your data.

"when I use one label with multiple images ... " -- that does not explain anything.

if you want us to reproduce your problem, we need your data, and code for a minimal test case.

berak gravatar imageberak ( 2017-10-30 02:36:27 -0600 )edit

@namlool. I used 2 images or more of same person on python 3.5.

supra56 gravatar imagesupra56 ( 2017-10-30 03:50:33 -0600 )edit

This is the code I'm using. 1. few labels with one image each - works. 2. one or two labels with few images each - works 3. 3 labels (or more) with few images on one of them throw the exception

void Train(array<String> images, array<int> labels)
    {

        std::vector<cv::Mat> cvImages;
        std::vector<int> cvLabels;          

        msclr::interop::marshal_context oMarshalContext;

        for (int i = 0; i < labels->Length; i++)
        {       
            const char* filename = oMarshalContext.marshal_as<const char*>(images[i]);
            cvImages.push_back(cv::imread(filename, CV_LOAD_IMAGE_GRAYSCALE));
            cvLabels.push_back(labels[i]);
        }                       

        (*d_model)->train(cvImages, cvLabels);
    }
namlool gravatar imagenamlool ( 2017-10-30 06:08:48 -0600 )edit

please again, add a check, if imread succeeded (and only then push_back() anything)

also check images.size() == labels.size()

also, just to make sure it's not that -- try without any clr/cli/managed code. (mixing opencv (RAII based) and clr code is a terrible idea)

(*d_model)->train -- what's d_model ?

berak gravatar imageberak ( 2017-10-30 06:24:06 -0600 )edit

*d_model = cv::face::createFisherFaceRecognizer(d_num_components, d_threshold);

namlool gravatar imagenamlool ( 2017-10-30 07:43:24 -0600 )edit

the EXACT type of d_model, please ?

berak gravatar imageberak ( 2017-10-30 10:54:09 -0600 )edit

cv::Ptr<cv::face::facerecognizer>* d_model = new cv::Ptr<cv::face::facerecognizer>();

namlool gravatar imagenamlool ( 2017-10-30 11:19:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2018-06-29 12:19:04 -0600

JY gravatar image

I have the same problem. Open CV 3.4.1, C++. Feeding this csv to train the model:

./faces/face003.jpg 3
./faces/face005.jpg 4
./faces/face009.jpg 7
./faces/face011.jpg 8
./faces/face014.jpg 10
./faces/face016.jpg 11
./faces/face018.jpg 12
./faces/face019.jpg 25
./faces/face021.jpg 13

All 3 face recognizers (LBPHF, Eigen and Fisher) train OK and output a prediction when fed with a test image.

If I change the csv to for example:

./faces/face019.jpg 12

(Label 12 now has 2 reference images face018.jpg and face019.jpg) Then I get the same error message as the OP.

The other recognizers do not throw that exception when trained with the same data set which kind of hints that the problem does not seem to be with the training set but with the training algorithm used by FisherFace.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-30 02:24:45 -0600

Seen: 292 times

Last updated: Oct 30 '17