Computer Vision – Visual Coin Counter

, , Leave a comment

I started to pick opencv (computer vision) for learning. I’ve been fascinated with this technology and what it can do. Today, computer vision is on our phone camera to find face and set the focus, or trigger the shutter when we smile, or following the object we lock. Let’s pick an example, Facebook. FB recognise the faces in an uploaded photo. CV technology allows FB to suggest friends found in that photo to be tagged. And even, FB learns from your past tagging, build information from collected faces, so it can improves its accuracy of suggestion. Another example is surveillance camera like in Bourne movies, the camera scans multiple faces at once and search for someone matching. It is real CV application. Last year, Google release Google Vision API that open even bigger opportunity to use the visual data to recognize, quantify even more to trigger physical world. Self-driving car is one of top application of computer vision and sensors.

I purchased a book to start the learning journey in cv world. The book promised that it would be easy to learn and apply. I tried to follow the basic steps of image processing and drawing shapes like rectangular, circle and mask it to the image. I am not finished with the book, but so far it is easy to follow.

I use my 3rd Raspberry Pi device for CV. It is Raspberry Pi 3 with 16 GB storage, equipped with Pi Camera version 1.3 and integrated LCD 3.5 inch screen. This 3rd unit is intended for desktop computing, entertainment and imaging (point-shoot camera, dashboard camera, computer vision). The 5 GB remaining space is the result of giving space to Retropie + ROMs, Pixel Desktop, Kodi and OpenCV as the last joining function.

I set my own goals in this learning process, the first two are to measure the distance between my car and car in front. The 2nd is to make self-driving RC car. Well, it is still long road to reach the goal, but the journey is enjoyable.

About counting coin, this is one of practice that the book explains. The difference from the book is, the counting that I do is not from a photo.  I like to have something direct, a real-time counting, from a live video.

Counting coin is an easy task for our brain, but definitely not for a computer. The idea is simple, computer to count objects from what camera is seeing. From the computer point of view, this involves some steps for the computer to capture the image, separate the object from the background, then identify the object by its edge, find contour and finally count. During these processing steps, the camera take continuous capture.

Curious about what happens back in the computer’s kitchen? Here is the process tour:

  1. Capture original image
Fig1. Original frame captured by Camera

2. Convert to grayscale

Fig2. Convert the frame to grayscale

3. Apply blur

Fig3. Apply gaussian blur

4. Find the edge

Fig4. Edge finding

5. Find the contour

Fig5. Find contour and draw green line around the contour

6. Count number of contour

Fig6. Count the contour and print in screen

The camera is continuously capturing the image and computer to process each image sequentially. And this process is repeated forever until break key is pressed.

Raspberry Pi 3 hardware is enough to perform all those steps without any problem. The time from capturing the image to the processing of 1st step till the 6th is fast. I think it is around 18-20fps (my estimation), if the capture size is 500px. Giving a good frame rate to the video, although may not be as smooth as 30fps video, but certainly more than sufficient for the job. Hat-off to Raspberry Pi hardware that make this possible!

Facebook Comments
 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.