Skip to main content

Don’t hesitate to say “Hello, Machine Learning”

 

Almost all developers and computer science enthusiasts wish to master the art of machine learning at some points. But most of them find it very difficult to start with. If you are one of them, you are in the right place. It’s very normal for beginners to route themselves into the right trajectory. Don’t worry about anything. I am here to help you out.

Trust me. You will be able to neglect the fear of machine learning at the end of this article. I am not going to waste your time with a lot of theories. Instead, I will directly jump into the action. Theoretical knowledge is important. But you don’t need to worry about them now. You’ll eventually understand everything.

“Machine learning is nothing but let the Machine learn something

Yes, you read that correctly. It is that simple! So, we have to teach the machine first. Wait a minute! How do we teach the machine? Well, that’s where the data get into the picture. What computer knows is just ones and zeros. So let’s give ones and zeros and build our face detection application.

We will be using a few tools and libraries with python, such as OpenCV, Numpy, etc. Don’t get panic if u didn’t hear these words before. OpenCV is a library used to build powerful applications. They will give you the trained models (trained by a massive amount of data). So, If we need a face detection model, we can get the model from them and use it in our code.

It’s widely used and supports different languages. I prefer to go with python that way you can get a lot of community support as well. Numpy is another library that supports the model to run. We won’t be using it in our code, but in the background, it will help to run the program. So, no need to worry about that now. As a first step make sure you installed the python and you have pip package manager. then use the comment given below to install the OpenCV in your local machine.


As I mentioned earlier, OpenCV has a lot of trained models where we could use them for different purposes. Here, we need to get the specific trained model for face detection. one way of doing it is by having the model as an XML in the project. Click here to download the particular file. After that, you can add it to the project. Create a python file in your project folder and start writing the code.


First, we need to import the OpenCV in our program just like other libraries. Then we are creating an instance of our trained model using the CascadeClassifier method (line #5). When we have an array of the camera, it will be indexed from 0. So, we are just taking the default one in a variable which is 0 (line #9). Then we are running the loop to keep the camera open in the GUI until the user press “1”. Inside the loop, we are just iterating through the frames that are being captured on the webcam. So we can identify the face in each frame using our model by separating the coordinates (line #15). Your coordinates will be something like the following one.

Here you are getting a two-dimensional array. So, each property of the main array is a face detected in the particular frame and the values inside that property array are going to be the identified coordinates. For example, [0][0] which is 244, and [0][1] which is 364 are the bottom left corner of the detected face, [0][2] which is 55 is the height of the first face and [0][3] which is 55 is the width of the first face.

Alright, we identified the face. Now what? Well, let’s draw the rectangle around the face. You have to draw rectangles for all the faces we identified in the frame. To achieve this, we have to draw a rectangle based on each property of the main array. That’s why I have another loop in the code (line #18). To draw the rectangle in the frame, we can make use of the method in the OpenCV (line #19). So, this rectangle method takes few parameters. The frame where we are going to draw, bottom left coordinates, top-right coordinates, and the RGB mix to get the outline color. So, we are using our “frame” variable right away. The bottom right coordinates are the first two elements of the array, the left top coordinates just adding the width and height to the first two properties of the array and in the RGB for each color. It takes the value out of 255 (we are generating the random number for all three colors to make the rectangle bit colorful). After that, you need to display your entire frame while it keeps capturing. For that, I just used the imgshow method in the main loop, which takes two parameters. Those are the name and the frame.

That’s it. Congratulations..! you have successfully developed your first face detection application. Just go ahead and type python <your python file name>.py in your console. You can see the magic.

I believe this would be helpful to get rid of the fear of getting started. Now you are ready to explore more things in this particular domain.

Further resources for learning

OpenCV Cascade Clustering tutorial : OpenCV: Cascade Classifier

Git repo for the source: vithushanms/ML-Demo (github.com)

Thank you all for taking your time to read this. I am so thrilled to see what you are going to build in your journey….Have a great learning ahead!

LinkedIn: msvithushan
Instagram: Ivithushan 

Comments

Popular posts from this blog

Batch processing in modern Java applications with Spring Batch.

In the world of software development, Batch processing has been one of the challenging areas to implement in the early stages. But these days there are plenty of solutions available out of the box in the frameworks and platforms to do batch processing. In this article, I will share my experience with one such tool, Spring Batch. This will enable you to do batch processing by configuring this with your existing Spring Boot applications. Before we jump into the Spring Batch let me brief you about batch processing. the name might make you fear a lot about it in case if you are new to this. It’s nothing but processing the transactions (data) as small chunks or groups without any manual interaction from the user of the application. You may ask why you want to do that. The answer is because it has a lot of benefits in terms of performance and the efficiency of the application as you deal with a large dataset.  Now let’s understand how it’s going to work and how we are going to implement this

What inspired spaceX to perform a historical achievement

As we know on Saturday, May 30th at 3.22 p.m EDT SpaceX has successfully launched the crew dragon’s demo-2 with NASA astronauts Bob Behnken and Doug Hurley on top of Falcon-9 . For American soil, it’s a 9 years gap from the STS shuttle. Also, this is the first privately-owned space vehicle to bring humans to Low Earth Orbit. The biggest question is “How the SpaceX managed to do this?”. If you want to know the answer you have to know the journey of SpaceX from the beginning. In 2002, SpaceX was formed by Elon Musk and Tom Mueller (Present CTO of SpaceX) with the vision of colonizing humans in the Red Planet. In the early 2000s, SpaceX was a joke for the space exploration community. Everyone knows that transporting humans to Mars is a big deal. Still, the biggest achievement in mars is NASA’s Curiosity Mars Rover. Elon Musk was very clear about this at the time when SpaceX was founded. Also, his fortune was not enough to go for launch at that time. But they were ready to face the challen

FaaS in Action with AWS + Serverless Framework for Java Developers

Serverless is becoming popular and Function as a Service is one of the trends in the serverless world. So being familiar with this technology is a really good addition to the profile as a developer. But from the very beginning of serverless, the community was preferring to use javaScript as the programming language. The reason for that is Serverless was initially made for less compute-intensive and more I/O intensive services where the JavaScript is performing well. So, that leads JavaScript to hold nearly 90% of the serverless world. But moving forward the way we use serverless and utilize computational power has changed. So there is nothing wrong for a Java developer to try out the FaaS and build comprehensive services. Therefore, I will be giving a practical example for developing an API in Java and deploying it in the AWS cloud. There are a few prerequisites to follow along Basic knowledge developing an API Basic idea about AW