detectMultiScale returns incorrect face values
Hi,
I am trying to detect faces from one image usinf face_cascade.detectMultiScale, but it returns a faces vector with 258235440 size. I'm using opencv 3.1.0 x86 version. Exploring the vector I can see that some values have x and y coordinates with negative values. The image actually does not conatins faces. The image is 1920x1080 24 bits rgb. The xml used is haarcascade_frontalface_alt.xml contained in data folder in opencv3.1.0 code.
This is my code:
bool Util_Faces::detectFace(const cv::Mat &img, cv::Rect &rect)
{
try
{
std::vector<cv::Rect> faces;
float ratio = 5.0;
float invertRatio = 1 / ratio;
int newCols = (int)(img.cols*invertRatio);
int newRows = (int)(img.rows*invertRatio);
//Scale image to 1/5 factor. (Image is 1920x1080 24rgb
cv::Mat imgGray;
cv::resize(img, imgGray, cv::Size(newCols, newRows));
cv::cvtColor(imgGray, imgGray, cv::COLOR_BGR2GRAY);
//-- Detect faces
Util_Faces::face_cascade.detectMultiScale(imgGray, faces, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE);
if (faces.size() == 0)
return false;
cv::Rect ajustRect = faces[0];
rect = cv::Rect(ajustRect.x*ratio, ajustRect.y*ratio, ajustRect.width*ratio, ajustRect.height*ratio);
return true;
}
catch (std::exception ex)
{
int a = 0;
return false;
}
}
Anyone knows why am I receiving this values?
Thanks.
" I'm using opencv 3.1.0 x86 " -- os ? bits ? compiler ?
i'm almost sure, that this is related to your other question (a linkage problem)
I'm using it in a 64 bits system, Windows 10 Enterprise 64 bits. OpenCV and my solution are compiled with Visual Studio 2015 x86 (Win32). The thing in this case is that It doesn't throw any error. It throws one when I try to create Rectangle with negative coordenates.