Training a Cascade Classifier - OpenCV Object Detection in Games #8

preview_player
Показать описание
In this tutorial, we train an OpenCV Cascade Classifier entirely on Windows to detect objects in a video game in real-time. Making your own Haar Cascade isn't complicated, but it can be a lot of work. This project is a great intro for beginners to Machine Learning. In this video I explain the Machine Learning basics, and walk you through the implementation of training and using your own model for computer vision in Python.

0:42 Machine Learning basics
2:28 Haar Cascade Classifier explained
4:04 Gathering the positive and negative images
7:06 Creating the negative description file
8:59 The positive description file
9:41 Installing opencv_annotation, opencv_createsamples, and opencv_traincascade on Windows
12:19 How to use opencv_annotation
15:17 Fixing Error: Assertion failed...
15:45 How to use opencv_createsamples
18:06 How to train a model with opencv_traincascade
22:24 How machine learning training works for image classifiers
23:06 How to use a trained model for object detection
25:59 How to train a better cascade classifier
29:00 What is overfitting?
30:27 Arguments used for my best Haar Cascade Classifier model

Normally when we program something, like when we write a function (for example), we expect certain inputs (like the parameters in our function). And then at the end we'll end up with some output (like the return part of a function). And in the middle, to get from the input to the output, we write some logic (if statements, loops, all that stuff).

With Machine Learning it's exactly the same, except that middle part is replaced by a Machine Learning model. So with Machine Learning you're not writing any of your own logic anymore, instead you're trusting this mysterious dark jumble of multi-dimensional calculus to transform your inputs into your desired output.

And at first your model won't know how to do... what you want it to do. Its output will be no better than random guesses. To get the output we want, we must first train our model. We do that by showing it lots of input examples, and for each example we tell the model what we want the output to be. Once it has seen enough examples, a well trained model will be able to accurately predict what the output should be given some new set of inputs.

That's the super summarized version of how all Machine Learning works.

In our case, our input is going to be screenshot images from the video game we're playing. And the output we want is a list of rectangles that identify the objects we're trying to detect. And fortunately for us, OpenCV's Cascade Classifiers are designed to do exactly that.

The way a Haar classifier works is it looks for features in an image, very much like the ORB feature detection we talked about in the last video. And it looks for these features in different layers. So at the top layer it will be looking at large features that span nearly the whole image window, down to the bottom layer where it’s looking for very fine details. This makes the end model fast enough to detect objects in real-time, because it can quickly reject areas of the image that fail to match the features in the top-most layers. And it can spend more time analyzing areas of the image that are good candidates, by studying those finer details.

Hopefully you have a general understanding now of how Machine Learning works and what makes a Haar Cascade Classifier unique. The great part is, the code for all of this is very straight forward.

The art of doing this well actually isn't so much in the code, it's more in gathering the data to train your model with. To get good results, you need quality data, and you need lots of it.

Now we need two types of data: We need the positive images - which are images that contain the object we're trying to detect... and we need negative images - which will be screenshots from the game that don't contain our object at all. The Machine Learning algorithm needs to see both what is and what is not the object in order for it to learn.

Рекомендации по теме
Комментарии
Автор

This is literally the best programming channel
I’ve ever seen

Brakerjw
Автор

This video is way too awesome. I rarely provide any comments in the web, but this video is so educational and well worth it to pass by. This is my very first machine learning video that I've watched and learned. You should really become a lecturer in some institute to pass on your knowledge. This video alone deserve a million thumbs up. Keep up the great work! I'll be looking through your channel for more videis :)

EDIT: By the way, do you have plans to create a video like this, but covering CNN? I recently did lots of reserach and found out CNN is more capable as compared to Haar cascade.

Lincoln_Poh
Автор

I don't always give a comment, but when I do it's to the epic series! Damn good bro. Keep up the good job. I'm watching you.

psmith
Автор

Super underrated. Thanks a lot for all of the information

WvyyFPS
Автор

I've struggled with looking through and understanding the OpenCV docs for Haar Classifiers. Thank you so much.

austingulotta
Автор

Absolutely fantastic man. I never thought I'd be casually setting up machine learning, debugging, scrapping it and coming up with better results..all testing on my favorite games. Cheers mate.

steelederic
Автор

This is the first series I am actually following on YouTube, where I am not 3 years too late. Great content! I enjoyed every video so far, even though I know alot of the stuff in this one as I am currently writing my bachelor thesis in the field of machine learning.

emperorpenguinv
Автор

You have helped me a lot when it comes to learning to program. Your channel alone has taught me from a single video then playlist from other channels

ravenebonscale
Автор

Very interesting and well explained, thx Ben 😊

mrdjangofreeman
Автор

This is the video with most likes that doesn't have a dislike that i've ever seen! Good job :p

footdle
Автор

This was AWESOME!!! Much more comprehensive than the docs!

actellimQT
Автор

Thank you so much! This is a wonderful series. This is my foundation for my opencv projects. I like the way you code and document. It's always complete and easy to understand.

doctorglock
Автор

thank you for this. doing this series making easier for people like me to learn these. thankss

once
Автор

You are simply awesome. your interest to teach along with the strain that you took to collect the training data shows it all. Please keep on doing this good work. God bless you.

rikkujoseph
Автор

Great video! Exactly what I needed for a project I'm working on. It's great to get a walkthrough to "grandfather" us through the process.

georgecarder
Автор

I watched tutorials in my own language but I didn't understand it as well as I do now. Thank you very much

narcisopascoal
Автор

You should really be bigger your content is better than most

espvolt
Автор

Best haar cascade tutorial i've watched! Keep up the good work!

andreivladescu
Автор

I really love and enjou your concent.
I haven't meet much youtuber who make programming and ai video like you did.
I hope this channel grow more and become great.

masfergi
Автор

I've been looking for a tutorial and I didn't got anything from them. and thankfully I found your channel you are describing things easily and I understood everything I need to.
thank you so much Ben.
keep going building great tutorial

mohammadsaleh