Tutorial: Real-Time Object Tracking Using OpenCV

Tutorial: Real-Time Object Tracking Using OpenCV


Found this video useful? $1 PayPal Donations are very much appreciated, thank you. https://www.paypal.com/cgi-bin/webscr...

For tutoring rates and business inquiries, please email kyle.hounslow@gmail.com


A simplified method for tracking objects in a webcam stream. In this video we use Visual Studio 2010 and OpenCV.

DOWNLOAD SOURCE FILE HERE (right-click, Save link as):
https://raw.githubusercontent.com/kyl...

Tutorial made on a 64-bit Windows 7 machine and OpenCV 2.4.3.
Closed Caption:

hello everyone my name is Kyle I'm a
fourth-year electrical engineering
student from the University of British
Columbia and today we're going to be
running on the track objects using
opencv libraries
after completing this tutorial you will
have the basic tools needed for tracking
objects in real time you're going to be
able to utilize them in more advanced
applications such as robot vision making
this video shown here
so you're going to need for this
tutorial first off you're going to need
to install opencv on your computer
we're also going to need some basic c++
college if you have installed opencv on
the computer you can use my tutorial on
installing and i recommend you do that
first before returning to this tutorial
the goal is to Tori ilysm to make a
super robust system where you can buy
any object at any time and then you see
what I'm going to be showing you how to
do is the very first step in learning
how do you track objects using computer
vision
what i mean by that is we are going to
be taking kind of a quick and dirty
approach this
you know what we're going to be
following just kind of two step process
first we're going to filter out the
colors that were interested in which
involves a couple steps which we're
going to be covering shortly as well as
finding the contours in the filtered
image which involves a few steps so
we're also going to cover
shortly after the collective thing
this is very much an interactive lesson
today I'm gonna have to ask you to pause
the video and download the source file
from the link below so we can follow
along together and tackle this problem
we're going to open a visual studio 20
and I create new project
- you went there to console application
I mean it just like the source file
click next console application put on
empty project commissioned can go over
the solution explorer and you're going
to right click on source files are going
to add the source file that you
downloaded once in my desktop this
navigate to wherever you saved year
source file
so the first thing we're going to do is
we're going to go to the property
manager click right here
we're going to put the debug going to
add existing property sheet
so I same line and I mean projects
folder so that all my projects i can
just go back a couple of directories and
just select it
that's what's called opencv debug 243
and double click on that and not just
links all the libraries so we can use
these two right here
for our application today
so now is a good time to go back and
start looking over the steps are about
to follow to achieve this object
tracking the first step that we're going
to be doing is going to be worth the
image from the PGR color space to HSV
color space colored objects are easier
to filter in the HSV color space and
there are many reasons for this but I
strongly encourage you to check out the
wikipedia page on the HSV color space
for more information on lights used in
image processing applications and see
what I'm talking about here from the
right in the HSE events on the left is
the RGB see that in HS p.m. at some of
the colors on the on the page are going
quite rightly you can see that would be
much easier to filter the your
application
are you go ahead and try it yourself
going going to build a project on your
left you should see the HSV color space
photo on the right of the gr you can
find on Jack and fold it up and see that
your object will most likely go Valerie
compared with the HSV color space we can
take this image and we can filter out
the pixels between a minimum and maximum
value of their HSE values going to show
you how popular here i'm going to build
the project again
rearrange a few things here
I made a set of sliders here which you
can use to adjust the minimum and
maximum HSV values so we're going to
we're going to filter out the color
orange here let me show you how in the
name of the game here is to keep the
color orange white in the binary image
on the bottom left
just by trial and error you can start
dragging the slider bars and if you drag
it too far the the orange will turn
black
I just need to adjust the p-values a
little bit and should be a filtered
orange square on the binary image the
white pixels are denoted as a one in the
black pixels is a zero so we can now
search through the binary image look for
the ones and we'll know that that set of
pixels is the area that we're looking
for
I'm going to do it again so reset the
HSV minimum maximum value so we're going
to try and filter out the Green Square
this time
so seeing kind of procedure to start
dragging in the minimum and maximum
values and just be sure to keep degrees
wear white
now we filtered out the green squares
law and just in case you're wondering it
also works for the Blue Square
no problem so go ahead and try it for
yourself
be sure to get good at it because this
is an important step when you're trying
to track objects by the color
it's time to go through some of the code
that we have written so far
so
I have to find the minimum and maximum
hsd values here
those are the values that we've been
manipulating in the sliders
now to make the sliders or call track
bars
we just defined in the create track bar
function the value that we're going to
manipulating so it seems to be a slide
this slider each mean values going to
have
according to change
so we're going to mean we can see that
we define some matrices to all their
images
you've got to find a video capture
objects and we've opened the webcam at
position 0
we then started a loop where each each
iteration
we're going to review the frame from the
camera feed we're going to get going to
convert the color to HSV I thought about
that earlier
we're going to take this HSV image and
we're going to filter between a minimum
maximum which are the values that we've
been controlling by the slider burgers
or something you may have noticed that
there are still some noise after your
image such that your you , can be
filtered out a hundred percent
now there's a way to fix this we're
gonna have to apply what's called some
morphological operations
i'm going to go over these in the next
section though
opencv implements these morphological
operations by its dilate any broad
functions
what the road function does it a there's
any white space such as your is your
noise
those little white specks you might be
seen it's gonna be rolled into them so
it's going to make them smaller or maybe
even non-existent with the dilated
function it's going to take the
remaining white space that we have and
we might have not that much because we
can roll it into the object that we want
to track as well
it will take that small amount of white
space that's going to dilate it's going
to make it much larger so that we can
have a nice definitive object that we're
tracking going to show you a visual
representation of what I'm talking about
here
this is our original image is still got
the noise around the outside of the
bunch cannot fully up and to the right
of it is what it looks like after being
eroded now as you can see all the white
specks used to be around it are now are
now missing
this is great we built it up the the
noise that uh that would have been
disrupting our object tracking algorithm
and we left with a nice little image its
kind of missing a little bit of pixels
in the middle
so how we're going to fix that is we're
going to now dilate the image seen on
the right here and as you can see the
remaining white space from the eroded
images now dilated so large that we have
a nice definitive object with your track
you might see you a few little specks
here and there in the dhall ada village
and we can easily get rid of those just
buy fresh holding between a minimum and
maximum area
you can go and try to yourself to go
back to me and we're going to change
this movie and use more mobs or change
it to true then scroll down here we're
going to see its usage right here
if it's true it's going to call a
locally made more pop function that I
made
let's go check out this more box
function you can see that defined the
erode element
it's a rectangle three pixel by pixel
live and also a dilated element which is
it pixel by pixel wide
they're both rectangles using
rectangular structure elements as much
less computationally intensive you can
see that first I called your own
function a couple times and passing year
old element and then I called dilate
function a couple of times passing the
dial yelled after searching the boolean
flag to true and rebuilding your project
you can try and filter the object again
you'll see that it's much more clear
with less noise
now that we have a nice clean filtered
binary and it's ready to move on to the
final step we're going to use open cds
find concourse punching and what we're
going to input into it it's a clean
filtered binary image that it just made
and it will open a vector of contours
which is the the outline of each white
space that's found in the binary image
we're going to use the moment method and
we're going to input in the victor
contours that we just got from the fine
contrast function this thing out put the
XY coordinates of the largest contour
defined by its inner area so the area
that the contours and compass
so here the contours being drawn to the
frame on the right to imagine them all
killed in like hear that's the area that
we're looking for
so after all this we should have our
tracked object on the screen so let's go
have a look at a how we're actually
going to do this year
so it back to the top verbing function
will find the billion called track
objects are going to set its true
then scroll down and see where this is
used to be find it here if this is
choose will call track filtered object
which I made a little function for it up
up top
very here
like I said before we make a vector of
contours which is a vector of vector
points
we didn't call the fine contours
function and that passing are filtered
image and then we're going to call the
moments method we're going to pass in
the contours
don't worry about completely
understanding all this stuff
this tutorial is really about the coding
aspect of it's more about the method
behind fast object tracking in image
processing all right so go ahead and try
yourself
make sure the track objects to be
variable is set at the right a little
example here the decide to track a golf
ball
you can see it's not a hundred percent
accurate but it definitely does the
trick
and like i said this is just a very
quick and dirty way of the tracking
objects
if you want to get more consistent
results you've got to have nice lighting
in the room and also a base still
background
this is the motivation of a attach this
video this is that i use basically the
exact same method to track the motion of
a kite and then get its velocity its
position its setting everything for my
senior electrical engineering project
where were generating electricity from
an airborne
congratulations you be this far I hope
this tutorial helped you
you have any questions or comments leave
them below and I will try my best to get
back to know other than that
thanks for watching

Video Length: 13:11
Uploaded By: Kyle Hounslow
View Count: 485,044

Related Videos
OpenCV (All Versions) - Easy Installation Guide and Sample Project (VS 2010 C++)
OpenCV (All Versions) - Easy Installation Guide and Sample Project (VS 2010 C++)

A step by step guide on installing OpenCV for Visual Studio 2010. Found this video useful? $1 PayPal Donations are very much appreciated, thank you. https://www.paypal.com/cgi-bin/webscr... OpenCV download: http://sourceforge.net/projects/openc... Some copy and pastables: Additional Include Directories: $(OPENCV_BUILD)\include Additional Library Directories: $(OPENCV_BUILD)\x86\vc10\lib **UPDATE** Version 2.4.6 Additional ...
Video Length: 07:49
Uploaded By: Kyle Hounslow
View Count: 287,968

OpenCV Tutorial: Real-Time Object Tracking Without Colour
OpenCV Tutorial: Real-Time Object Tracking Without Colour

Found this video useful? $1 PayPal Donations are very much appreciated, thank you. https://www.paypal.com/cgi-bin/webscr... For tutoring rates and business inquiries, please email kyle.hounslow@gmail.com In this tutorial we will look at real-time object tracking using the method of sequential images. This allows us to track objects without the use of colour filtering. We code in C++ using Visual Studio 2010. Start by downloading the following zip file: ...
Video Length: 22:31
Uploaded By: Kyle Hounslow
View Count: 263,430

Traffic counting based on OpenCV
Traffic counting based on OpenCV

A simple example of background subtraction and frame difference method. Accuracy may vary.
Video Length: 02:41
Uploaded By: excellentSK
View Count: 251,141

OpenCV Python Neural Network Autonomous RC Car
OpenCV Python Neural Network Autonomous RC Car

Bridgewater State University COMP 502 Project, May 2015 Self driving RC car: OpenCV neural network - Steering Haar-cascade classifiers - Stop sign and traffic light detection Ultrasonic sensor - Front collision avoidance Raspberry Pi - Data streaming (video and sensor) Arduino - RC car control BGM: [Hunter x Hunter 2011] Original Soundtrack 3 28 - Holding A Card File üm-ün Source Code:br ...
Video Length: 03:06
Uploaded By: Wang Zheng
View Count: 246,410

Beaglebone: Video Capture and Image Processing  on Embedded Linux using OpenCV
Beaglebone: Video Capture and Image Processing on Embedded Linux using OpenCV

In this video I look at how you can get started with video capture and image processing on the Beaglebone. It is an introductory video that should give people who are new to this topic a starting point to work from. I look at three different distinct challenges: - How do you capture video from a USB webcam under Linux - How do you capture image frames from a USB webcam under Linux - How do you use OpenCV to capture and image process frames so that you can build computer vision ...
Video Length: 31:40
Uploaded By: Derek Molloy
View Count: 186,099

Raspberry Pi camera module openCV object tracking and following self balancing robot
Raspberry Pi camera module openCV object tracking and following self balancing robot

http://roboticssamy.blogspot.pt/ Vision: Raspberry Pi model B Raspberry Pi camera module OpenCV OpenCV working with Pi camera thanks to this great tutorial: http://thinkrpi.wordpress.com/2013/05... Thank you Pierre Robot setup: Carbon fiber chassis 2000 mAh 11.1V LiPo battery PIC24 microcontroller Murata ENC-03 gyro MMA7361L accelerometer NEMA17 step motors RC 1/8 Buggy wheels Link to ...
Video Length: 01:01
Uploaded By: 74Samy
View Count: 154,983

How to create the OpenCV binary files yourself - Part 1
How to create the OpenCV binary files yourself - Part 1

This is a video version of the OpenCV tutorial here: http://opencv.itseez.com/doc/tutorial... Part 2 may be found at:
Video Length: 12:29
Uploaded By: OpenCVTutorials
View Count: 147,743

Laser tracking projection with Kinect and OpenCV
Laser tracking projection with Kinect and OpenCV

I finally downloaded OpenCV (an open source computer vision library) and spent some time learning about how to use it. It was actually surprisingly painless once I got the hang of it, and there are lots of things you can do once you feed it an image (in this case, the depth image). What I did was rig it to track contours on the depth image, and attempt to pick out a rectangular object. Then, by using the detected location of the corners, I can apply it as a perspective transform to ...
Video Length: 02:41
Uploaded By: marcan
View Count: 134,022

Copyright © 2025, Ivertech. All rights reserved.