Haar classifier trouble accurately detecting circles

Hello,

I’m using OpenCV Haar Classifier to detect circle spheres or bubbles of different radiuses in images. To ensure identical colour ranges, we use thresholded black/white image, so circles are drawn in Black colours over White background. Then we train using synthetic images of circles of different radius sizes (black lines over white background of course).

From the observation, it correctly detected some of the circles, but there are too many false positives, where it draws non-existent circles. For the detection, we use the facedetect.cpp code available on OpenCV website, but slightly modified to removed the nested object. To validate, we have trained it again using concentric circles, and tested over circles without concentric/child circles, and it did not detect those. It was not meant to detect them.

So I’m lost as to why we are seeing non-existent circles? So it detect circles or even larger radius where there are non-existent circles. I’ve tried both the HAAR & LBP feature. We’ve trained it in multiples stages that took hours, but to see speedy results, we reduced training to 4 stages, and even tried to increase the MaxDepth (since it is using Boosted trees), but MaxDepth may not be working. So negative samples are just pictures that mostly doesn’t represent circles totalling 2638, while for this test, positives were around 3075, but it terminated early at the 2nd stage, since the FA may be less now.

I’m trying to understand what’s the best way to do this? I mean this is a single class problem, just to detect circles of different radiuses. From my observation, I doubt the classifier scales the input images, which is ok for us, since the synthetic contains circles of all radius sizes anyway.

Looking at the output:

NEG count : acceptanceRatio    2638 : 1
Precalculation time: 0
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|0.0015163|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 0 seconds.
--
POS count : consumed   3075 : 3075
NEG count : acceptanceRatio    0 : 0
Required leaf false alarm rate achieved. Branch training terminated.

Input parameters:

opencv_createsamples -info c0/d0/out2/o2.p -vec c0/d0/out2/o2.vec -bg c0/d0/neg.txt -num 3075 -bgcolor 255
Info file name: c0/d0/out2/o2.p
Img file name: (NULL)
Vec file name: c0/d0/out2/o2.vec
BG  file name: c0/d0/neg.txt
Num: 3075
BG color: 255
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 24
Height: 24
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
Done. Created 3075 samples

opencv_traincascade -featureType LBP -data $HOME/vas/I/p/sub/group/cir5/c0/d0/out2 -vec $HOME/vas/I/p/sub/group/cir5/c0/d0/out2/o2.vec -bg $HOME/vas/I/p/sub/group/cir5/c0/d0/neg.txt -numPos 3075 -numNeg 2638 -numStages 4 -numThreads 20 -maxDepth 10 > $HOME/vas/I/p/sub/group/cir5/c0/d0/out2/r.out

it would be easier if you just showed those

so far it sounds like you picked the wrong approach

Why do you think it is the wrong approach. Is the opencv_traincascade not designed for these types of problems?

The info file contains correctly bounded rectangles of the input circles. For examples, it detects extra circles like those 3. I thought maybe this may be related to the CASCADE flags (ROUGH_SEARCH, SCALE_IMAGE,etc), but it appears not:

yes, unfortunately this is the problem.

haar cascades need reproducable texture, all you have is an outline.
maybe it’s easier to understand with an image:

But it’s similar. The sample you’ve provided is from Viola’s paper and the tutorial. In essence, I believe the interpretation is those section of the regions have similar intensities. how is that different from the outline I have provided? It should be an 100% match. By texture you mean, the image is missing many data. let’s try that approach and see

just to clarify, your image shows 5 (overlapping) circles, not a (single, composite) “object” ??

Using the cascade.xml into images with texture, still produced many face positive circles. Getting the classifier to work is just too much hassle.

I’m even looking at the source code to understand why it detects all these false circles. It’s almost as if it isn’t worth it !

Is this the detectMultistage function that’s misbehaving ?

Shows 4 overlapping circle and not a single composite one. There are others, but I provided this, to give an idea of the problem. I actually thought it might make sense to provide the background colour as a negative sample, but no results from that.

There are other better designed object detector that performs excellently in this area but HAAR appear very simple, yet very difficult to implement and use

1 Like

can you tell us your “use-case” ? what is it all for ?
where do you get those circles from ?

All I can say, is we want to use it to detect objects like the face detector on OpenCV tutorials :wink:

could this be the mis-doing of the detectMultiStage() function ?

no, please be more explict, else this is not going anywhere…

I am trying to use it to detect multiple circular objects in an image.

i’m giving up on you.

That’s it. I am using it as an object detector, to detect multiple similar circles in an image, but as you can see, it also detect false circles.

I mean, I’m not sure if this require tweaking or looking more at the detectMultiScale() function flags or parameters

I have actually tried changing the numNeighbors and CASCADE flags in detectMultiScale(), I think to 0 neighbors and CASCADE_ROUGH_SEARCH, and I ended up with circles every where all over the entire image dimensions… so I’m trying to see if those flags influence it somewhat.

the minimum sizes actually influence the objects detected, but ideally it should not falsely detect an object that doesn’t exist.

the issue here is that you did pick the wrong method.

its disappointing performance should be telling you that. stop banging your head against a wall.

I’m saying “wrong” in the sense that trying to make cascades work for your task would require enormous effort, with uncertain results (i.e. could turn out to be a waste of effort), while other methods would solve this trivially.

there are methods specific to circles. the Hough transform comes to mind (OpenCV has it). there’s also the Radial Symmetry Transform (RST) and the FRST (fast RST).

Honestly, Hough transform also exhibited similar behaviour. I am not aware of Radial symmetry transform, but we wanted to see if a classifier approach will work with excellent results if you DO NOT SPECIFY the exact object location.
If one specifies the exact object location in the INFO file, it will match it accurately without any issues but that defeats the entire purpose of object detection:

I think someone also complain about Hough Transform and Haar classifer here:

Fast Radial Symmetry Transform Implementation - OpenCV Q&A Forum

the mere existence of “complaints” has no merit. that person has failed to present their problem (no data) so any judgment they made is impossible to verify, hence meaningless.

if you want to be lazy, post a bunch of data. people like me are bored enough that you just might get a proof of concept for free.

in fact, that’s how novices should approach problems: ask experts for opinions, instead of picking a hammer and whacking things that aren’t nails.

So you are saying it is impossible to use HAAR classifier to detect multiple circular/spherical objects, even when positive samples of the same object description is given to the classifier ?

no I’m not. I said this:

to rephrase: you are making your life needlessly hard.

again, the more data you post, the better our suggestions will be. a single example is better than none, but not as good as a whole bunch of examples.