Ask Your Question

Train cascade classifier for game screenshots

asked 2020-03-27 09:42:20 -0500

VoDHei gravatar image


Sorry for my bad english :)

THE OBJECTIVE : Detect a fantasy character on a screenshot (yellow rectangle on the image) like this :


I have screenshot extract from a video game.

All screenshot are from the "boss achievement screen". Here some screenshot negative samples :

I need detect if a specific boss is on the screenshot. I need to detect only this boss :

Important Note : it is a static screen, no movement. very little variance.

I installed opencv successfully. I execute the 'face-detection-rectangle' example from node-opencv (, it's ok to detect 'mona lisa' face ;)

Now I want to detect boss from screenshot. I think this is not exactly face detection but more object detection.

I do the "Cascade Classifier Training Tutorial" (, but...

THE PROBLEM : my training is bad, and I can't detect boss on my images. The Bad detection result :


1 / I have only one positive image, I think it's ok, because it's a static screen no movement, and very simple detection needed i think ?

2 / The positive image : What is the difference between - use the complete image (like this : and specify dimensions in like this : 'positives/positive-boss-complete.jpg 1 570 193 326 265' - or crop the image (like this: and specify dimension in like this : 'positives/positive-boss-crop.jpg 1 0 0 326 265'

3 / Negative images samples : What sort of image does a need ? Screenshot from other bosses ? croped screenshot or complete screenshot ? I have only 20 boss screenshot, Should i use images that have nothing to do with the game or only use game screenshots ?

4 / Create sample : I use this command 'opencv_createsamples -info info.dat -bg bg.txt -vec samples.vec -w 100 -h 100' in order to create samples. Is '-w 100 -h 100' ok for my context ? Should I use '-maxxangle' '-maxzangle' and '-maxzangle' and which values ?

5 / Train cascade : I use this command 'opencv_traincascade -w 20 -h 20 -data data -bg bg.txt -vec samples.vec -numPos 1 -numNeg 20 -numStages 10'. Have you some observations ?

Thanks for your help.

edit retag flag offensive close merge delete


my training is bad, and I can't detect boss on my images.

give up that idea, it will never work.

you cannot train anything successfully on a single positive image, your game figures contain pose variation, etc.

berak gravatar imageberak ( 2020-03-28 03:02:13 -0500 )edit

I installed opencv successfully.

thats dead. use current 3.4 branch instead

example from node-opencv

not maintained from opencv, and we cannot help with it

berak gravatar imageberak ( 2020-03-28 05:55:31 -0500 )edit

Ok thanks, I will install 3.4.

VoDHei gravatar imageVoDHei ( 2020-03-29 11:36:46 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2020-03-28 14:24:07 -0500

HagymaGyilkos gravatar image

What if instead of trained detection you use template matching?

Since it's static, and has very low variance, the image should look wery similar, and the position should be consistent too, so you dont't need to use the full image for matching, which can be heavy on resources, you only need an estimated ROI as a subMat. Use the image of the boss as input, and given the low variance, there should be a close match (significantly lover than other bosses) at the position of the boss.

After the template match, you look at the minimum value, and decide a minimal threshold, below you accept it as detected.

It fullifies your objective, but has zero inpact on your knowledge about Cascade Classifiers, nor answers your questions.

edit flag offensive delete link more


Yes ! I use Template matching and it's ok. Thanks

VoDHei gravatar imageVoDHei ( 2020-03-29 11:34:39 -0500 )edit

answered 2020-03-29 04:56:40 -0500

ComputerVisionary gravatar image

1 Always better improving the dataset with a lot of generated samples. Otherwise you will 100% overfit the target.

2 -

3 Look at 1.

4 100 x 100 is a huge size for a cascade, main problems: noise / ram allocation. Try models up to 50x50 pixel.

5 take a look here pls:

edit flag offensive delete link more


thanks for your answer. I decide to use Template Matching more appropriate.

VoDHei gravatar imageVoDHei ( 2020-03-29 11:35:58 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-03-27 09:42:20 -0500

Seen: 68 times

Last updated: Mar 29