From f08996bd37f7f80fc22d3c59073c80bc3fc37222 Mon Sep 17 00:00:00 2001 From: Eric Christiansen <ericmartinchristiansen@gmail.com> Date: Thu, 26 Jul 2012 16:55:54 -0700 Subject: [PATCH] asserted in LBPH code that images must have a single channel --- modules/contrib/src/facerec.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index 696606859..6676728ce 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -734,6 +734,12 @@ void LBPH::train(InputArray _src, InputArray _lbls) { // get the vector of matrices vector<Mat> src; _src.getMatVector(src); + for (vector<Mat>::const_iterator image = src.begin(); image != src.end(); ++image) { + if (image->channels() != 1) { + string error_message = format("The images must be single channel (grayscale), but an image has %d channels.", image->channels()); + CV_Error(CV_StsUnsupportedFormat, error_message); + } + } // turn the label matrix into a vector Mat labels = _lbls.getMat(); CV_Assert( labels.type() == CV_32S && (labels.cols == 1 || labels.rows == 1)); @@ -760,6 +766,10 @@ void LBPH::train(InputArray _src, InputArray _lbls) { void LBPH::predict(InputArray _src, int &minClass, double &minDist) const { Mat src = _src.getMat(); + if (src.channels() != 1) { + string error_message = format("The image must be single channel (grayscale), but the image has %d channels.", src.channels()); + CV_Error(CV_StsUnsupportedFormat, error_message); + } // get the spatial histogram from input image Mat lbp_image = elbp(src, _radius, _neighbors); Mat query = spatial_histogram(