Ask Your Question
0

OpenCV Python face detection fails on image with high levels of background light

asked 2017-07-18 13:51:26 -0600

boshal gravatar image

updated 2017-07-20 11:01:10 -0600

I am running a typical face detection using OpenCV's (python3) haarCascades, and it does not seem to recognize my input image, presumably because of high levels of background light. Is there any way to get around this, or any special pre-processing I can do? I have tried clahe, but that does not seem to work, and I also tried equalizeHistogram, which also did not work. What other methods can I use to process the image so that face detection will work as intended? This is the image I would like to detect

EDIT: it could also be a viable possibility that the glasses have something to do with it, as the top part of the glasses frames seems to obstruct the eyes of the subject... Could this also play a part in the failure of the face detection?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2017-07-21 09:35:36 -0600

i tried your image with the code below and result is OK

could you post your code that did not find the face...

#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

#include <iostream>

using namespace std;
using namespace cv;


int main( int argc, const char** argv )
{

    Mat image;
    CascadeClassifier face_cascade;
    //-- 1. Load the cascades
    if( !face_cascade.load( "E:/git/opencv/data/haarcascades/haarcascade_frontalface_alt.xml" ) ){ printf("--(!)Error loading face cascade\n"); return -1; };

    image = imread("e:/test/15004038028938638.jpg");

    std::vector<Rect> faces;
    Mat image_gray;

    cvtColor(image, image_gray, COLOR_BGR2GRAY);
    equalizeHist(image_gray, image_gray);

    //-- Detect faces
    face_cascade.detectMultiScale(image_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));

    for (size_t i = 0; i < faces.size(); i++)
    {
        rectangle(image, faces[i], Scalar(255, 0, 255), 3);
    }
    //-- Show what you got
    imshow("result", image);
    waitKey(0);

    return 0;
}
edit flag offensive delete link more

Comments

Also use the newest frontal face model, it is much robuster.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-07-24 07:02:32 -0600 )edit
0

answered 2017-07-18 15:57:47 -0600

KjMag gravatar image
edit flag offensive delete link more

Comments

I tried all the methods on that page, and it doesn't seem to improve face detection.

boshal gravatar imageboshal ( 2017-07-20 09:47:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-18 13:51:26 -0600

Seen: 2,199 times

Last updated: Jul 21 '17