Why does my image recognition training in Opencv generate transparent samples?

Asked

Viewed 620 times

5

I’m using Opencv and trying to generate a file. vec to do image recognition training, but whenever I file and try to read it, I see images as if some parts of my positive are transparent! (I apologize for not making the images available in the question itself, but I don’t have enough reputation for it, so I put the link at the end to the drive that contains all the images cited)

Here’s the command I’m trying to execute:

opencv_createsamples -vec 483.vec -img 483.png -bg 483.txt -num 5 -w 128 -h 128 -maxxangle 0 -maxyangle 0 -maxzangle 0

This is the 483.png:

483.png

This is an example of background I used:

001 png.

This is a sample result that is in . vec:

training.png

So I tried to add a green background to 483.png and add the following parameter in the command:

 -bgcolor 00ff00

And the result was:

green training.png

What am I doing wrong? Why doesn’t 483.png get solid on top of the other icon? Or did I get the concept wrong? Because in the Opencv documentation, it mixes the names "Negative" and "background" and, for me, they are equal in the -bg part of the command, but different in the -bgcolor command. The idea is not to put another icon as a background, but the context of the image it will be in? Still, I have the impression that 483 should not be "transparent".

Link to the Drive: click here

  • Good question, which generated a good response from a good user.

1 answer

7


The documentation unmixed the names "Negative" and "background". I think you got it wrong anyway.

One "negative image", in the context of training an Opencv recognizer, means an image that does not contain the object of interest (which will be recognised). Similarly, a "positive" image in that same context means an image that contains the object of interest.

Remember that this utility serves to create new examples from an existing one. Thus, the concept of negative image has nothing to do with the concept of background color. The "background color" serves only to indicate to the utility which are the pixels that should be considered as transparent, when creating new examples. The documentation says the following:

-bgcolor

Background color (Currently Grayscale images are assumed); the background color denotes the Transparent color. Since there Might be Compression artifacts, the amount of color tolerance can be specified by -bgthresh. All pixels withing bgcolor-bgthresh and bgcolor+bgthresh range are Interpreted as Transparent.

Note the dots I marked in bold. First, the original image is considered/treated as grayscale (only 1 color band, that is, only one luminous intensity value per pixel). But since you can pass color images (with 3 bands, that is, 3 values per pixel) the conversion uses a tolerance value defined by another parameter. Finally (and more importantly), ALL pixels whose color falls in this range are considered as transparent when creating the new example.

That is, although you see green only in the background of the original image, there are certainly other pixels that also have the FF value for the green band (although they do not appear as green for you because they have different values of 00 in the other two bands of red and blue).

The issue then is that you do not need to produce an example with green background to use the utility and replace by transparent some green pixels. Again, according to the documentation, the idea of this and the other parameters is only to increase the randomness of the examples (positive or negative) for the coach:

Please note that you need a large dataset of Positive samples before you Give it to the mentioned Utility, because it only applies perspective Transformation. For example you may need only one Positive sample for Absolutely Rigid Object like an Opencv logo, but you Definitely need hundreds and Even thousands of Positive samples for faces. In the case of faces you should consider all the race and age groups, Emotions and Perhaps Beard Styles.

So, the single Object image may contain a company logo. Then a large set of Positive samples is created from the Given Object image by Random Rotating, Changing the logo Intensity as well as placing the logo on arbitrary background. The amount and range of randomness can be Controlled by command line Arguments of opencv_createsamples Utility.

That is, the idea of using this parameter is only to generate more "random" examples (with background variations, in your case) to increase the efficiency of the detector in the "real world" (where luminosity variations, for example, are quite common). If you pay attention to the other parameters of this utility you will see that there is also option to rotate the images, for example. After all, rotation is also a very common variation in the real world. Imagine the detection of a human head. As the head may be "lying on the shoulder", either you arrange positive example images that already contain the head in this rotation, or use the utility to generate examples rotating the images you already have. If your trained classifier doesn’t have images with this rotation, he won’t be able to detect rotated heads in the "real world".

In conclusion, the answer to your question "Why My Image Recognition Training in Opencv Generates Transparent Samples?" is: because you requested. :)

EDIT:

If you haven’t done it yet, do it this tutorial. It is very useful and intuitive. There the author describes the following:

opencv_createsamples generates a large number of Positive samples from our Positive images, by Applying Transformations and distortions. Since one can only Transform so Much out of one image until it’s not a Different version anymore, we need a little help to get a Arger number of samples out of our relatively small number of input images.

In free translation:

opencv_createsamples generates a large number of positive examples to from our positive images, when applying transformations and distortions. Since someone can only turn a little (manually) an image until it is no longer different, we we need a little help to produce a large number of examples from our relatively small number of entree.

That is, it should be easy to realize that it makes more sense to use this type of tool to produce useful variations of positive images (those containing the object of interest). After all, to have negative images (which do not contain the object of interest) just grab anything (pictures of cats, soccer balls, trains, women, cars, women, yachts, women, mansions, women, etc.).

  • 1

    (pictures of cats, soccer balls, trains, women, cars, women, yachts, women, mansions, women, etc) kkkkkk

  • I don’t understand what I can do to fix this then. The tutorial you gave me uses linux commands, something I could not do in windows or using Cygwin :( Anyway, how should I proceed so I have reasonable samples? What type of image should the "-bg 483.txt" file contain? I tried putting only a background image of the game board (a brown square with few details), I specified its color (with -bgcolor 786956) and the generated samples were very solid, but the test with the training was quite flawed. Should I put random pictures of the game in -bg?

  • For when I do this, he falls into that same initial problem: 483 becomes transparent with parts of the other images "inside". And another: if Negative and background are distinct things, where enter the negatives? Because at no time are there parameters that specify negatives, only specify backgrounds.

  • The answer to "where the negatives enter" is: they do not enter (in this tool you are using). The tutorial is on Linux, true, but there’s more for you to read it carefully and understand the process. The tool opencv_createsamples exists to help you create training examples. If you already have enough examples, you don’t even need to use it. Negative examples go into the classifier training (along with any other example you produce with the opencv_createsamples). You leu the documentation carefully?

  • About "how should I proceed so I have reasonable samples?" I would say try to use the images you already have? without producing anything randomly (with opencv_createsamples). If your resulting detector is not good enough, then you try using positive images (only positive ones!) to generate more random examples with this tool. Dai uses the color you want for the background. The idea is just to give randomness. It doesn’t matter.

  • The documentation that you passed is open in my browser already some 4 days and straight I return to read it haha I was confused even. Anyway: I’m trying to do some tests here and I find it strange that it always generates a filing cabinet 2KB, no matter how many samples I put in... I tried to use more than one stage also for 200 positive and 200 negative, but it gives the error Train dataset for temp stage can not be filled. in stage 1, only rotate 0. What may be the problem?

  • It always generates a similar file because this file doesn’t have the samples, only the data that he learned from them. Without more details I don’t know what can be this error. But anyway, if it is a new problem you should open another question. :)

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.