Drawing with Computer Vision


Using OpenCv and my webcam track and draw on my screen.

Published on April 15, 2021 by Claudia Chajon

Python computer vision webcam machine learning

1 min READ


Drawing a logo in the air is harder than it looks.


See the code


I’m sure you know which logo I am referring to.

Seeing these awkward attempts, I thought, “Come on, it can’t be that hard. You know that shape! Just do that!”

— OpenCV has entered that chat —

Using OpenCV and my webcam I was able to isolate certain colors and use them to essential track an object across the screen and draw with it.

Isolating colors of highlighters.

Through trial and error, I found that lining the markers all together made it easier to isolate each one individually.

When I did them one by one, the algorithm confused multiple colors for each other and had trouble isolating the markers separately.

So what originally looked like great isolation of the object just became a mess once I lined up all the markers together.

mask

Using a cv2.findContours, I created a circle at the tip of the marker with the object’s bounding box.

mask_2

Check out that pink marker. Chef’s kiss.

tracking

I wanted the specific color of each highlighter. Which I found on a fan of neon colors page.

color_values = [[211, 73, 244], # hot pink
                 [51, 255, 128], # green
                 [255, 47, 149], # purple
                 [43, 246, 204]] # yellow

dots

I needed the colors in BGR format to enter as values for a list that the program could reference when filling the bounding box circles.

With 80 lines of code I am able to draw on the screen and attempt to make the Disney logo perfectly.

But I can’t do it, yet!

Let the record show that I have never claimed that I have great hand-eye coordination.

Also, my Hispanic skin is being detected as the color yellow.