Ask Your Question

setimage in CascadeClassifier

asked 2012-11-26 10:42:45 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I would like to know how to evaluate face detector at a particular location. I see that there is CascadeClassifier::Setimage option, but I get segmentation fault when I try to use it.

I looked at the objdetect.hpp, and found that the ::Setimage option as described in OpenCV documentation page, is actually in protected mode rather than public. Also I see that ::runat is protected. I think there is some error in the way it is currently done, or I may be wrong.

I am trying to hack a bit into the detection code. Till then If someone has an idea or can give an example file on how to use it efficiently, Please let me know.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-11-27 01:44:50 -0600

Siegfried gravatar image


it looks for me that you are using the CascadeClassifier. Which image type do you pass to the method setImage()? The only supported image type is CV_8UC1 (see: See online documentation of CascadeClassifier::setImage()).

Have you seen the Face Recognition with OpenCV tutorial? This tutorial briefly explain the new face recognition algorithms in OpenCV and how they can be used.

To evaluate a particular location in the image you only have to put this ROI to the FaceRecognizer::predict() method.

edit flag offensive delete link more



Hi, I am trying to evaluate the face detector at only one location. If you look at objdetect.hpp, and the documentation for CascadeClassfier::setimage, there is some difference. According to the documentation, and the implementation the member functions are protected, and cannot be accessed. I have looked at Face recognition, and it is not what I need currently. I know that giving the ROI is one way to do it, but a simple check for time consumed to do this way shows that it take a lot of time. I need a way to evaluate a single window at a time.

venky gravatar imagevenky ( 2012-11-27 04:31:00 -0600 )edit

Hi, if you really want to evaluate a single window at a time. I only now 2 hacks. The first one is to implement a own class which is derived from CascadeClassifier. You can then access the methods setImage and runAt from this class, since they are protected and not private. The second is to use the detectMultiScale method with your window roi as input image. The detectMultiScale() method downscales the input image by scaleFactor, as long as the detector fits into the downscaled image (see the break condition at line 1147 in If you now put a input image (your roi) with the same size as the maximum object size and a large scaleFactor the method will evaluate only one window.

Siegfried gravatar imageSiegfried ( 2012-11-27 07:51:46 -0600 )edit

Hi, Thanks for the suggestions. I am using haar cascade classifier and was actually looking at haar.cpp where finally the evaluation takes place. Since, I have to be careful at evaluating the performance (speed, and accuracy) of different approaches, I need to probably modify haar.cpp or write a different class to reach my objective. I just did a quick experiment of using detectMultiScale() with fixed size (min=max), at say random 1000 locations and the result: it took a lot of time compared to processing the full image at one go.

After loading the CascadeClassifier, I call setimage and I get segmentation fault. The sequence of calls are shown below: CascadeClassifier cascade; cascade.load(cascadename); cascade.setimage(gray);

I will go in detail haar.cpp and other files.

venky gravatar imagevenky ( 2012-11-27 08:22:42 -0600 )edit

It's probably too late, but I did it by creating new class which is derived from CascadeClassifier. Then I implemented metods runAt() and setImage as public for this class and it works.

magdagrs gravatar imagemagdagrs ( 2013-04-15 16:51:33 -0600 )edit

Question Tools


Asked: 2012-11-26 10:42:45 -0600

Seen: 1,173 times

Last updated: Nov 27 '12