Custom Object detection - training my own detector but cannot get training tool to work

Hello there,

for a project i need to enable my programm to detect a given object in an image to extract object position and the objects bounds.


Since we already use opencv for the image processing we do, the idea was to use opencv’s Cascade Classifier to detect said objects.

Now the issue is: for all i can find on the web i only see people praising how simple it is to detect faces using the already given pretrained model coming with opencv.
The again there is supposed to be a tool to do this as described here
I tried building this with cmake to no success.
Is there any way to download this as a prebuild tool or a noobfriendly description of how to aquire the training tool for haarcascade classifiers?
I basically wasted this whole day on finding a solution but the only things i find in relation to this topic are mostly year old outdated posts and they all just show how to apply the pretrained facerecognition classifier.

Any help, hint or advice in this regard is highly appreciated. In case you need more info or think that using the cascade classifier is a dumb idea anyway let me know if there are better ways :slight_smile:

1 Like

it only works with the 3.4 opencv branch (4.x removed c-api parts nessecary for this)

no.

sadly, that’s true in most cases ppl try ;(
.quick checklist:

  • do you have a few hundred positive images to train it with ?
  • can your object show up rotated ?
  • does it have some kind of “reproducable texture” ?

(no, yes, no == “dumb idea”)

anyway, here’s the tutorial

p.s. can you explain the image ? is there really a reflective surface ?

1 Like

Hey berak,
thank you for the quick reply.
I already had the tutorial you linked posten in my OP. Issue with this tutorial is that it basically just says: yeah well use the tool opencv_traincascade but i just cannot find/get/manage to build this. Using this will probably be a piece of cake but aquiring it… well…

Regarding your other notions:
i can generate hundreds of pictures if necessary → yes
the object in question will only show up in the rotation i want it to
not sure what you mean about “reproducable texture” but i guess the answer is yes.

What you see in the image is a reeeeaaaly tiny piece of plastic seen through a microscope camera (thus a lot of noise in the image) on glass plate on a 3 axis stage. So yes the lower half is a reflection.

If using the cascade classifier is indeed a dumb idea as you mentioned would you be able to tell me if you’d see a better/easier way to detect this object? I already tried a naive approach using some binarythreshold/cannyedge/contour detection but did not find settings that led to reliable results.

My goal is to reliably find the left most edge of the object in the image so that i can move the object to gently “touch” with another object on the left side.

1 Like

needs real life images, not synthetic ones.
(you can “augment” 5000 images to 15000, but not 3 to 3000 in a meaningful way)

btw, you can also try to train a HogDetector (similar performance, similar problem scope). sample here which is also easier to configure (all you need is a folder with cropped positives and another with negs)

ps: again, what about the reflection ? it looks harmful

1 Like

thx for the recommendation. Will check that out tomorrow.

What i meant by “i can create more images” is that i can sit down to just take more images.

And yes the reflection is somewhat harmful but i can not remove the object from the glass plate. I can change the lighting so that the glass is basically a white base instead of a black one but that leaves reeaaally low contrast between the pastic object and the background.
Thus my current attempt is to leave the “background” unlighted and try to cope with the reflection somehow.

1 Like

a polarization filter can remove reflections. that’s a physical filter, not a digital filter.

to discuss approaches, it would help us to see many pictures that accurately represent the variety an algorithm would have to deal with.

oh man, that we did not think of this ourselves… Will definetly see if there are fitting polfilters for those cams.

other then that there will for now at maximum be changes in the lighting situation or depending on the zoom of the cam that there are other of the same object in the current image as well. (really blurry at top and bottom, a bit of dirt on the left)

since i cannot put multiple images in one post as new user here goes another one with less light but more “texture”

But either way, i’ll check out the suggestions you guys provided and buy a polfilter for the cams. That might already help out a lot so that my first filter approaches work without the need for actual classifier approaches.

Thank you so much!