#Coding4Fun – How to control your #drone with 20 lines of code! (12/N)

Buy Me A Coffee

Hi!

Today code objective is very simple, based on a request I received from internet:

The drone is flying very happy, but if the camera detects a face, the drone will flip out !

Let’s take a look at the program working:

This one is very similar to the previous one. I also realized that I may need a better camera to record the live action side by side with the drone footage, but I think you get the idea. The command to make the drone flip is “flip x”, where “x” is the direction. In example:

"flip l" # flip left
"flip r" # flip right
"flip f" # flip forward
"flip b" # flip back

Here is the code:

As I promised last time, in next posts, I’ll analyze more in details how this works, and a couple of improvements that I can implement.

Happy coding!

Greetings

El Bruno

References

My Posts

#Event – (update) @devdotnext now in virtual mode ! #devdotnext2020

Buy Me A Coffee

Hi!

These are strange days, however we all try to do our best to move forward. An important part of today’s behaviors is to try to avoid big events. That’s why, in the last 2 weeks, we get news about events being cancelled all over the world.

I have a plan to visit Colorado, US, in a couple of weeks for the Dev.Next event. However, due to Covid-19, the event was postponed to August (more information here).

The amazing organizing team, decided to face this with a big smile and organized a mini virtual version of the event. This is the official announcement:

dev.next is happy to announce a mini digital event on March 24, 2020. The event is free to attend. We will post link here on March 24th. Recordings from the event will be available later. Please check back here for links to the recordings.

dev.next digital event

I’ll be part of this Digital / Virtual Days hosting a remote session around AI and Anomaly Detection, with code and without code !

Take a look at the agenda here.

Happy coding!

Greetings

El Bruno

#Coding4Fun – How to control your #drone with 20 lines of code! (11/N)

Buy Me A Coffee

Hi!

Today code objective is very simple:

The drone is flying very happy, but if the camera detects a banana, the drone must land !

Let’s take a look at the program working:

drone flying and when detect a banana lands

And a couple of notes regarding the app

  • Still use Haar Cascades for object detection. I found an article with a Xml file to detect bananas, so I’m working with this one (see references).
  • Using Haar Cascades is not the best technique for object detection. During the testing process, I found a lot of false positives. Mostly with small portions of the frame who were detected as bananas. One solution, was to limit the size of the detected objects using OpenCV (I’ll write more about this in the future)
  • As you can see in the animation, when the drone is a few meters away, the video feed becomes messy. And because the object detection is performed locally, it takes some time to detect the banana.
  • I also implemented some code to take off the drone when the user press the key ‘T’, and land the drone when the user press the key ‘L’
  • The code is starting to become a mess, so a refactoring is needed

Here is the code

In next posts, I’ll analyze more in details how this works, and a couple of improvements that I can implement.

Happy coding!

Greetings

El Bruno

References

My Posts

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (7/N)

Buy Me A Coffee

Hi!

I’m writing a series of posts about how to control a drone with Python and 20 lines of code, and once I reach to the point to read the camera feed, I’ve added a face detection sample. However this time I didn’t use the face_recognition python package I’ve used in this series, I performed the face detection using OpenCV and Haar Cascades. So, let’s explain a little what’s this.

Let me start quoting an amazing article “Face Detection using Haar Cascades” (see references)

Object Detection using Haar feature-based cascade classifiers is an effective object detection method proposed by Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001. It is a machine learning based approach where a cascade function is trained from a lot of positive and negative images. It is then used to detect objects in other images.

OpenCV comes with a trainer as well as detector. If you want to train your own classifier for any object like car, planes etc. you can use OpenCV to create one. Its full details are given here: Cascade Classifier Training.

And here we come to the cool part, OpenCV already contains many pre-trained classifiers for face, eyes, smile etc. Those XML files are stored in opencv/data/haarcascades/ folder (see references).

opencv github haar cascades files

Let’s take a look at a really [20 lines] sample code for face detection:

  • Line 6, we use OpenCV to load the haar cascade classifier to detect faces
  • Lines 9-20, main app
  • Lines 10-12, open a frame from the camera, transform the frame to a gray color scaled image and use the face cascade detector to find faces
  • Lines 14-15, iterate thought detected faces and draw a frame
  • Lines 17-20, display the webcam image with the detected faces, and stop the app when ESC key is pressed

And a live sample using a drone camera instead of an USB Camera

Bonus. Viola Jones Face Detection and tracking explained video

This is a long video, however is an amazing entry point to understand how the Viola Jones algorithm works.

Happy coding!

Greetings

El Bruno

Resources

#Coding4Fun – How to control your #drone with 20 lines of code! (10/N)

Buy Me A Coffee

Hi!

Back to some drone posts! I was kind of busy during the last weeks and now I can get back to write about the drone.

OK, in the last posts I described how to connect and work with the drone camera feed using OpenCV. Now with 2 extra lines of code we can also detect faces. Let’s take a look at the final sample.

drone camera and camera view performing face detection

In the previous image we can see 2 camera feeds. My computer webcam, where you can see how I hold the drone with the drone camera pointing to my face. And the drone camera feed, presented using OpenCV and drawing a frame over each detected face.

Let’s share some code insights:

  • As usual, I resize the camera feed to 320 x 240
  • The average processing time is between 40 and 70 FPS
  • I use a haar cascade classifier to detect the faces in each frame

Note: I need to write about Haar Cascades as part of my face detection post series.

In my next posts, I’ll add some drone specific behaviors for each face detected.

Happy coding!

Greetings

El Bruno

References

My Posts

#Personal – Kids and STEM: my 2 cents to #IWD2020 #PressforProgress #CDC2020

Buy Me A Coffee

Hi!

Some time ago I posted about the amazing experience I had at the Caribbean Developer Conference (@caribbeandevcon) in Punta Cana.

And if you are wondering “How this is related to International Women Day?”, let me share this video:

That’s Martina (my 10yo daughter) with Scott Hanselman talking about Computer Vision. She was part of the interview! And as I wrote before:

Scott was an amazing host, and we talked about how we can use Image Recognition systems in day to day scenarios, like garbage bin detection, smart parking lots and even to track our cat at home.

This photo is much more important than you think ! InternationalDayoftheGirl DayoftheGirl

International Women Day

Even if we are still a couple of days away of the official International Women Day, let me share my contributions and plan for the future.

My main 2 cents to the International Women Days is kind of selfish, however I strongly believe that support and encourage new generations to get close to STEM topics is a great way to support them.

That’s why, if you can, I strongly encourage to bring your kids (and/or your kid’s friends) to tech events. Share moments with them, introduce them to the speakers, attendees, helpers, etc on the event. They will learn new stuff; they will share some amazing ideas, and this is an amazing path for them to learn and know STEM!

It’s also important for us to acknowledge that men and women have different workplace experiences, so that’s why I hope that next generations won’t see a difference there.

And finally, please, let’s keep talking about this. I’m not an expert in this area, and the best I can do is to connect the dots and support some very specific scenarios. I’ll keep doing this !

And yes, Martina is also helping me now with my Drone and AI pet projects. You can see how much fun our pet Goku is having with the drone

Thanks Channel 9 and On.Net !

Note: And it seems that the other half of the family is not happy to be excluded of this post.

Happy coding!

Greetings

El Bruno

#Event – Materials and resources used during TechDay Conf, #techdayconf #techdayconf2020

Buy Me A Coffee

Hi !

I shared some knowledge around Machine Learning.Net last Saturday during the TechDays virtual conference. And, as usual, it’s time to share the resources I used in this session.

Full event

Slides

Resources

Happy coding!

Greetings

El Bruno