Or, How I Used a Tennis Ball to Play Pacman

Photo by Alex Escu on Unsplash

I’ve written about the Mean Shift Algorithm before, but I never gave a practical application of it. I ultimately felt unsatisfied by the article, so I wanted to revisit the topic and apply it to a real world situation.

The Mean Shift algorithm can track objects in real time by using color. The more distinct the color from the background, the better it works. While object tracking presents a huge topic in computer vision, I wanted to focus on the gaming.

Motion control, the art of tracking the physical movement of the player and translating it into a computer input…

A Practical Demonstration of Haar Cascades and Homography

Photo by Ethan Robertson on Unsplash

The introduction of augmented reality (AR) in smart phones ushered a novel approach to entertainment. From playing games like Pokémon Go to making funny faces on Snapchat, AR has become a commonplace phenomenon.

While these technologies seem advanced enough to borrow from science fiction, creating a fun, Snapchat-style filter in Python is surprisingly straightforward. In this instance, I’ll create a filter that places a pair of sunglasses on a face.

Using OpenCV to Detect the Foreground

Photo by Ostap Senyuk on Unsplash

We live in the era of video calls. Conducted over the internet and using whatever camera that comes with your laptop or computer, we broadcast our lives to our classmates, coworkers, and families.

Sometimes, though, we don’t want to broadcast our space. My office, like many others, has a few perennial pieces of clutter. I also have a guitar on the wall behind me, which doesn’t always scream professionalism.

As a result, Zoom and other video calling software includes a feature to hide your background, usually behind an image of your choice. …

Using OpenCV and Python to track objects by color

Photo by Kevin Mueller on Unsplash

Among the most demanded features of computer vision is object tracking. Unfortunately, this is also one of the most difficult aspects of computer vision to implement.

Not only does an object need to be identified, it needs to be identified quickly enough to render in real time while it moves. The object may change orientation or change its distance from the camera, which further complicates matters.

While still an adamant challenge in computer vision, the mean shift and cam shift algorithms present a simplified solution. …

Using OpenCV.js to find edges in video

The edges detected around my cat
The edges detected around my cat
The edges detected around my cat. Image produced by author.

Edge detection is a fundamental tool in computer vision. By using sharp contrasts in brightness, general outlines and shapes can be found in an image. Often used as a filter to find distinctions between items in a photo, edge detection offers a first stepping stone into object recognition.

OpenCV offers a wide range of computer vision tools in C++, Java, Python, and JavaScript. Among them include an edge detection algorithm using the Canny method. Built with performance in mind, OpenCV’s implementation of edge detection can be interfaced with real time video with little to no noticeable latency.

While many examples…

Employing NumPy to Optimize Python Code

Photo by 𝓴𝓘𝓡𝓚 𝕝𝔸𝕀 on Unsplash

While Python remains easy to use, quick to learn, and offers an overabundance of external libraries that can do almost anything, it has one critical weakness: it’s slow.

Of course, to the human eye, its sluggishness seems negligible. Usually Python only lags behind other programming languages by milliseconds; however, when iterating over millions or even billions of data points, it quickly adds up.

NumPy offers a unique solution. While allowing users to still write Python, it converts it into well written C code specifically optimized for numerical analysis.

Using NumPy arrays can increase a script’s performance by one or two…

An Explanation for Splitting Data into Training and Testing Sets

Photo by Isaac Smith on Unsplash

On my first job out of college, I was tasked with streamlining how a company made purchases. While a big project that encompassed many factors, such as lead times and order quantities, the most challenging part was determining how many units would sell over time.

With lead times in excess of 2 or 3 months, I needed to accurately predict if a certain product would run out before a new shipment came. It was a balancing act, because if I underpredicted how much product would sell, the company would run out and lose sales. …

A Quick Guide on Writing your Own tl;dr

Photo by Aaron Burden on Unsplash

Project Gutenberg offers over 60,000 full length books. Wikipedia contains over 55 million unique articles. Wattpad has over 400 million short stories. In the age of the internet, there is no shortage of literature to read.

These numbers, however, are completely overwhelming. A person could spend a lifetime attempting to read the entirety of the internet and never scratch more than a fraction of the surface.

The ocean of written material creates a paradoxical problem: because there’s an overabundance of information, finding relevant information becomes more difficult.

Automatically generating text summarizations may help the problem. Instead of leaving users to…

An introduction with a Python example

Photo by Jon Tyson on Unsplash

K-Nearest Neighbor Algorithm

K-Nearest Neighbor (KNN) is an easy to understand, but essential and broadly applicable supervised machine learning technique. To understand the intuition behind KNN, examine the scatterplot below. The plot shows the relationship between two arbitrary dimensions, x and y. The blue points represent members of group A and the orange points represent the members of group B. This will represent the training data for KNN.

A Primer with a Real World Demonstration

Photo by Pineapple Supply Co. on Unsplash

Retailers have access to an unprecedented amount of shopper transactions. As shopping habits have become more electronic, records of every purchase are neatly stored in databases, ready to be read and analyzed. With such an arsenal of data at their disposal, they can uncover patterns of consumer behavior.

What is Market Basket Analysis?

A market basket analysis is a set of affinity calculations meant to determine which items sell together. For example, a grocery store may use market basket analysis to determine that consumers typically buy both hot dogs and hot dog buns together.

If you’ve ever gone onto an online retailer’s website, you’ve probably…

Andrew Udell

Data Science Enthusiast | Code Junkie | Lifelong Student https://www.linkedin.com/in/andrew-udell-108802140/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store