You are on page 1of 3

instructables

Object Tracking - Detection

by HappyBacon

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.

https://youtu.be/rpQWRTpjWng

https://youtu.be/Mcdp1iLaZF8

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).

Object Tracking - Detection: Page 1


Step 2: MATLAB CODE

In this section you can find the Matlab code that I EDIT: some people asked me in the inbox for some
wrote. explanation of what the code actually do. So I've
slightly modified the code to show the image during
The structure is quite simple: the various steps of the algorithm, I hope it helps to
It will initialize the webcam, setting up the format and better understand it.
resolution, then it will enter a loop where a snapshot (The code is also updated, you can see that figure 1
of the video is taken and processed. is the old one with only the original image and
Then using "imfindcircle", a function implementing the detected circle, while figure 2 is the new one with the
hough transform, the object is detected and the 6 steps. You can easily comment/uncomment the
outline, center coordinates and radius are printed on figure you want to show. I strongly suggest to only
the image itself. use one at a time, otherwise matlab will flicker like
crazy switching continuosly between the two).
I have also uploaded a simple flowchart to better and
simply explain the code

Download
https://www.instructables.com/ORIG/FXJ/DY28/JE94VOE6/FXJDY28JE94VOE6.m

Object Tracking - Detection: Page 2


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:

//www.youtube.com/embed/Mcdp1iLaZF8

Download
https://www.instructables.com/ORIG/FKS/E4H2/JEIV3XNH/FKSE4H2JEIV3XNH.pptx

Step 4: RESULTS

Here you can find a couple of pictures and a short the image. I'm already working on it and I plan to
video showing the code working. publish the instructable in a couple of weeks or so.

In the two pictures you can see how the code is able Follow me if you want to stay tuned on the next steps!
to detect the object correctly even though the bed is
blue and with also my hand covering part of its shape. If you have any questions, and of course also advices
and critics, I will be more than happy to answer to
The next step will be to put the webcam on a pan/tilt them in the comments :)
mount and move it to keep the object in the center of

https://youtu.be/rpQWRTpjWng

Object Tracking - Detection: Page 3

You might also like