Using Open CV Computer Vision to detect the colour of M&Ms
By Lachi Agnew

Using Open CV Computer Vision to detect the colour of M&Ms

This blog post presents an intriguing use of Open CV Computer Vision to detect the color of M&Ms, as part of an Internet of Things (IoT) based M&M sorter constructed from Lego. The author explains the technical aspects of setting up a Raspberry Pi with OpenCV and creating a color filtering and object detecting algorithm. The application of cutting-edge technology in a relatable context makes the concept of computer vision understandable and exciting for non-tech enthusiasts.

This post is part of our series on How we built an Internet of Things based M&M Sorter using Lego. See the overarching blog here.

Computer Vision is really cool, the idea of a computer being able to "see" is fascinating not just for tech heads like me but for everyone I speak to about it! I'm especially excited when I actually get to play with cool new technology and actually show non-tech friends a practical example of what I have built. Beats out the other times I've talked about my work, I learnt the hard way that showing off logs from a blockchain isn't all that exciting.

Randall Munroe tist:

When it comes to computer vision, however, showing how a facial expression detector algorithm or a self-driving car works means my friends can get just as excited as I am. So when I heard we were developing an IoT device to sort M&M's at Sheda I got really excited to help, jumping on the project to develop the computer vision algorithm to sort M&Ms.

To get a proof of concept up, we decided to use object detection using OpenCV(Open Source Computer Vision) with colour filtering on a Raspberry Pi. In this post, I will go through the technical details on how I set that up.

To follow along with this you will need a Raspberry Pi with a camera module, however, if you don't have that you can follow along with any computer with a webcam.

Contents

  • Set up Raspberry Pi with OpenCV
  • Develop an algorithm for filtering colours and detecting the contours of an object using OpenCV

Sheda Ltd

Transforming wellness businesses with AI-powered personalization and automation tools.

HIPAA Compliant
SOC 2 Certified
Data Privacy Protected

© 2025 Sheda Studio Pty Ltd. All rights reserved.