Cascade training in OpenCV 3

asked 2017-11-27 09:35:03 -0500

pww gravatar image

My question relates to creating positive samples for use in cascade training for OpenCV 3. I wish to find an object with a rectangular shape that is approximately 45 pixels wide and 90 pixels high. The object may be orientated at any angle in the original image being searched. The original image and the object image are in Black and White (grayscale 0/255).

One option I am considering is to superimpose the object image on a background of grayscale 127 that is 100 pixels square and use the createsamples program to produce rotations between 0-359 degrees with the bgcolor parameter set to 127. The rotations would then be applied to the negative background images (also grayscale 0/255).

What figures should I give to the w and h parameters? Should it be a square (50 x 50 pixels) or a rectangle (22 x 45 pixels) keeping in mind that the object searched for could be horizontal and therefore 90 pixels wide and 45 pixels high? Presumably the w and h parameters in the traincascade program should be the same as used in createsamples?

Thank you for your help.

edit retag flag offensive close merge delete



what exactly are you trying to detect ?

berak gravatar imageberak ( 2017-11-27 09:52:52 -0500 )edit

Is this even remotely related to: ... where the user is looking for the rotation angle?

sjhalayka gravatar imagesjhalayka ( 2017-11-27 10:19:17 -0500 )edit

To berak - A playing card identifier from the top corner of a playing card. For example, the 6 hearts motif.

To sjhalayka - Sorry, no.

pww gravatar imagepww ( 2017-11-27 10:43:04 -0500 )edit

so, they are several different cards to detect ? (it gets more and more unlikely, that this is the right tool then)

berak gravatar imageberak ( 2017-11-27 11:00:35 -0500 )edit

To berak - The original image being searched would be a table top with a varying number of playing cards at different rotations. I have been working from the book OpenCV 3 Blueprints and thought I could adapt Face Detection techniques to detect possible locations where a card identifier has been found and then apply a Face Recognition routine to identify which card has been found. If there is a better and more efficient approach I should be pleased to hear. Thank you.

pww gravatar imagepww ( 2017-11-27 11:17:42 -0500 )edit

this won't work, imho. you can train a cascade only on a single object(symbol), and you can't vary the pose much (+-15°, maybe) cascade classifiers are the wrog tool here.

rather try to detect the outline of the playing cards, rotate that to vertical, crop it, and train an SVM or such on plenty of example train images (ohn and trying with the face-recognition classes makes some sense for this, too)

berak gravatar imageberak ( 2017-11-27 11:39:50 -0500 )edit

To berak - thank you very much for your help and I will look at what you suggest. Out of curiosity though, what would be the correct settings for the w and h parameters in my original approach - a square or a rectangle?

pww gravatar imagepww ( 2017-11-27 12:15:28 -0500 )edit

w and h should have the same aspect ratio as the original, unrotated card

berak gravatar imageberak ( 2017-11-27 12:24:35 -0500 )edit

To berak - thank you for your w and h response.

pww gravatar imagepww ( 2017-11-27 12:27:38 -0500 )edit