Ask Your Question
0

How does cvhaardetectobjects c2g works

asked 2013-06-12 04:53:17 -0600

Antonio C. gravatar image

updated 2016-01-23 11:31:50 -0600

i'm doing some experiments with violajones algorithm for my digital imaging university course. i need to know how the CvHaarDetectObjects() function, that receives in input a color image, transforms it in a grey scale image. i can't find this information in the documentation and it's hard to find it in the code.

thanks in advance

Antonio Castellano

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2013-06-12 05:17:27 -0600

berak gravatar image

CvHaarDetectObjects does not convert the img to grayscale. you've got to do that yourself before, using cvtColor().

and damn, use the C++ api, please!

CascadeClassifier cascade("opencv/data/hairycascades/bald.yml");
if ( cascade.empty())
{
    // could not find it
}

Mat img = imread("my.png");
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);

vector<Rect> faces;
cascade.detectMultiScale(gray,faces);
// process face-rects.
edit flag offensive delete link more

Comments

I also prefer to use the C++ API, but there might be reasons (e.g. performance) why someone would use the C API. You can suggest users to use the C++ API, but maybe in a nicer way :)

Ben gravatar imageBen ( 2013-06-12 06:00:37 -0600 )edit

ok, too harsh, maybe. but you won't get any performance boost out of the c-api, they're using the same code underneath. all you get is trouble.

berak gravatar imageberak ( 2013-06-12 06:05:18 -0600 )edit

Exactly. C++ code uses C code underneath in most cases, so the C++ API is just a wrapper, which costs performance. It's not much, but depending on your application, you might get a slightly better performance using the C API. And you only get into trouble if you don't know how to use it. But some people do know that and some of them produce even better code with it than with C++.

Ben gravatar imageBen ( 2013-06-12 06:21:43 -0600 )edit

ok, nice little flame war, let's settle it

berak gravatar imageberak ( 2013-06-12 07:15:53 -0600 )edit

It was not intended to be a flame. I was just trying to explain why there is a right to exist - and thus to use - for the C API in OpenCV ;)

Ben gravatar imageBen ( 2013-06-12 08:10:21 -0600 )edit

now, please go and give that guy an answer ..

berak gravatar imageberak ( 2013-06-12 08:19:07 -0600 )edit

:D I did. I think you're gonna like it ;) I didn't say you should not recommend the C++ API at all.

Ben gravatar imageBen ( 2013-06-12 09:05:11 -0600 )edit

than you all for the answers. i use the c api because i already know it and i can't spend so much time to learn the cpp api now. as i've understood the function uses one channel of the image. what i son't understand is how the iplimage where i load my images (and can load any type of image) became a 1 channel immage when sent to the function for detection.

Antonio C. gravatar imageAntonio C. ( 2013-07-02 11:30:20 -0600 )edit

Question Tools

Stats

Asked: 2013-06-12 04:53:17 -0600

Seen: 864 times

Last updated: Jun 12 '13