# Object Tracking - Detection

222

9

Posted

## Introduction: Object Tracking - Detection

The purpose of this project is to read the video of a webcam, find a circular object of a specific color (blue in this case) and track it.

Also, the code is robust enough to: - be able to detect the object even if part of it is covered - track only the circular object, even if something of the same color is present The code is developed in Matlab to take advantage of its built in library to access the feed of a USB webcam.

## Step 1: SETUP

The only equipment needed is a PC with Matlab installed (the USB webcam package of Matlab is also needed) and a usb webcam (in this case I'm using a Logitech C310 720p webcam, but any other usb webcam should be fine).

## Step 2: MATLAB CODE

In this section you can find the Matlab code that I wrote.

The structure is quite simple:
It will initialize the webcam, setting up the format and resolution, then it will enter a loop where a snapshot of the video is taken and processed.
Then using "imfindcircle", a function implementing the hough transform, the object is detected and the outline, center coordinates and radius are printed on the image itself.

I have also uploaded a simple flowchart to better and simply explain the code

EDIT: some people asked me in the inbox for some explanation of what the code actually do. So I've slightly modified the code to show the image during the various steps of the algorithm, I hope it helps to better understand it.
(The code is also updated, you can see that figure 1 is the old one with only the original image and detected circle, while figure 2 is the new one with the 6 steps. You can easily comment/uncomment the figure you want to show. I strongly suggest to only use one at a time, otherwise matlab will flicker like crazy switching continuosly between the two).

## Step 3: Functions Explanation

To better explains what the various functions do and how to use them in matlab I've prepared this simple powerpoint presentation.

For a (hopefully) better explanation, also watch the video at this link:

## Step 4: RESULTS

Here you can find a couple of pictures and a short video showing the code working.

In the two pictures you can see how the code is able to detect the object correctly even though the bed is blue and with also my hand covering part of its shape.

The next step will be to put the webcam on a pan/tilt mount and move it to keep the object in the center of the image. I'm already working on it and I plan to publish the instructable in a couple of weeks or so.

Follow me if you want to stay tuned on the next steps!

If you have any questions, and of course also advices and critics, I will be more than happy to answer to them in the comments :)

## Recommendations

• ### 3D CAM and CNC Class

360 Enrolled

• ### Trash to Treasure

We have a be nice policy.