File Exchange

image thumbnail

Tracking red color objects using matlab

version 1.1 (2.27 KB) by

This program just tracks all red color objects and draws a bounding box around them.

4.6375
86 Ratings

253 Downloads

Updated

View License

This program just tracks all red color objects and draws a bounding box around them. This works on the difference between frames concept. Every frame in the video is returned as an rgb image on which we can do image processing stuff.

Comments and Ratings (124)

liujiachao

thank u !!
%%%% SOLUTION for
% Error in getCameraInfo (line 4)
% What worked for me is to change this code:
% camera_id = camera_info.DeviceInfo.DeviceID(end);
% resolution = char(camera_info.DeviceInfo.SupportedFormats(end));
%%my solution is that Type 'imaqhwinfo' for a list of available ADAPTORNAMEs. to see whether u have install Support Package Installer or not

Anh Nguyen

thanks <3

Sergio San

Thanks!!!

Mukundettan

Thank you

vinod kumar

It is really amazing...
Great work....

How could this code work with two cameras simultaneously, like two eyes?

kuldip patel

thanks it is work properly

Error in redObjectTrack (line 20)
    data= getsnapshot(vid);

any ideas plz?

I'm currently using matlab 2016. However, this code keeps showing up:
Error in redObjectTrack (line 7)
vid = videoinput('winvideo',1);

I have all the adaptors. Does anyone have a hint? thank you

Dai Wei-Zhu

How can I catch else color object(modify where)?

yaser ku

thanks
pleas can send me the slide of this program
yasermare@yahoo.com

MD Rijwan

Thanks a lot Brother...I was searching for it from past many days..

Job

Job (view profile)

%% SOLUTION for
% Error in getCameraInfo (line 4)

% What worked for me is to change this code:
% camera_id = camera_info.DeviceInfo.DeviceID(end);
% resolution = char(camera_info.DeviceInfo.SupportedFormats(end));

% INTO THIS CODE:
camera_id = camera_info.DeviceInfo.DeviceID;
resolution = camera_info.DeviceInfo.DefaultFormat;

ahmed aghmadi

please i try this program but i have an error. it's :
??? Error using ==> imaqdevice.start at 91
Multiple VIDEOINPUT objects cannot access the same device simultaneously.

Error in ==> redObjectTrack at 15
start(vid)

>>>> please help me

thank you

Gul Rukh Khan

Thanks for your good work.
Highly appreciated.

Marco Grasso

thanks a lot

badri INFO

good

I have 2 errors:

Error using end
Incorrect cell or structure reference involving "end".
Most likely cause is a reference to multiple elements of a cell or structure followed by additional subscript or structure
references.

Error in getCameraInfo (line 4)
camera_id = camera_info.DeviceInfo.DeviceID(end);

Error in redObjectTrack (line 2)
[camera_name, camera_id, format] = getCameraInfo(a);

ali hussn

good

Its very good, I have complete RED, GREEN and Blue detection by minimum changes in your program but..
1.How can we detect this all color in single window, though i used 'hold on' its not working properly.
2.what changes i should make if i want to detect other color like yellow?
provide help please.

Aviv Yaacobi

Hello Bhargav,
I want to use your code on an mp4 file.
So i use the command "VideoReader" to read this file and the Matlab tool show me an Error - "Error using VideoReader/set
The name 'FramesPerTrigger' is not an accessible property for an instance of class 'VideoReader'."
How can you help me with this problem.
Thanks!!!

hamada brahim

thanks

KDN

KDN (view profile)

Hello Bhargav ,
It's nice work. Can you help me to detect brightness of red color and display it on screen, what if I have to switch from red to white.

thanks a lot

thanks it works perfect

thanks a lot

edofersan

Thanks a lot.

abirov

abirov (view profile)

Thanx for code, that is amazing .
Is it possible to teach camera for color tone from camera than track it ?

Hello mr A. Bhargav Anand,
Tq for sharing such an amazing code.
I have run the code but I got this error:

Error event occurred at 06:45:52 for video input object: RGB24_640x480-winvideo-2.
Unable to allocate memory for an incoming image frame. Use IMAQMEM to modify the frame memory limit.
Unable to allocate memory for an incoming image frame. Use IMAQMEM to modify the
frame memory limit.

Error in imaqdevice/getsnapshot (line 63)
    [snapshot, metadata] = getsnapshot(imaqgate('privateGetField', obj,
    'uddobject'));

Error in redobjectdetection (line 16)
    data=getsnapshot(vid);
 
Error using imaqdevice/getsnapshot (line 65)
A timeout occurred during GETSNAPSHOT.

Error in redobjectdetection (line 16)
    data=getsnapshot(vid);

what should i do?
plz help me to fix this problem.
TQ :)

i hv made a robotic arm with 3 servos and a camera at the top and i want my camera to detect red objects and moves my arm in these,so yr code is that i want mr.Anand but i need to add some code yet, that talks to servos.if u can help me i ll apreciate it...! Thanks!

Justin Kirk

ilin kang

Hello

I'd like to find a red circle.

Also I'd like to make a range of rectangle tool flexibly to find the red circle withing the range.

I'd appreciate your cooperation.
Please reply to hoyoung778@gmail.com.

Rajeev Pushp

interested

myint Nyan

burak

burak (view profile)

very impressive... ty

helwan ghgs

please Mr.Anand, can you give me your contact email?

My Regards

hello mr bhargav. what is algorhythm in this code ?
thanks for the code its amazing

Manoj Reddy

Hello Mr.Bhargav. Iam getting an error in function file(get camerainfo.m).
the error is
Error in ==> getCameraInfo at
camera_name=char(A.InstalledAdaptors(end));
??? Input argument "a" is undefined.
What should I do now?

Aisha

Aisha (view profile)

Mazinho

daniel grant

Excellent work.

The code works perfectly.Thank you a lot ! I have a different tone of red to recognize.Can you please hep me?I want to modify it to recognise all types of red.Thanks

asan masraf

Thanks for your efforts,
I would like to ask you if I want to change tracking object from red color to another color or may be for tracking some specific shapes, how can I do?

Qasim Ali

Büşra

Emre

Emre (view profile)

Hi, that is a great job. In my thesis, I need to find the shortest distance between a red circle center and a line. Do you have an idea about how could i do this? or anyone else?

Scratch that last comment, did not read all the older comments

Syifak Izhar

sky nku

Good job

Thank u so much !!!!!
It's working . . .

GREAT

daher

daher (view profile)

Hi. great job. i have a question if you dont mind. let us assume that we have to track the first noticed red object, and to keep tracking it whilst other red objects appear.. any idea how to tackle this issue without referring to the geometry of the objects?

sfl

sfl (view profile)

Wow.. Thanks a lot.
I was wondering, can we store all the X,Y values( that comes on webcam screen as we move the red object) in a program as output value..??

TRINAYAN

Hi,
Your code is great and so fast. I am having a problem .When i try to use the centroid coordinates to display a particular its showing the wrong results. I want to use this for a object following robot but when i use a if loop to decide which character to be sent its not sending correctly.

mooud

mooud (view profile)

this is great . thank you
code works perfect . easily can change the red color to green or blue by changing 1 to 2(green) or 3 in :
(data(:,:,1), rgb2gray(data));
i had a problem in objects were far from cam to recognize, which solved by reducing the number in :
diff_im = bwareaopen(diff_im,600);
still don't know how to extract the coordinates and save them ??

zetad yosif

ADNAN

ADNAN (view profile)

gud work

Anas Blue

hi guys how can I save the coordinates from this code into an array ??

thank you very much for code.

larry suide

Very good, but the last two lines of get_camera_info can give error; these work for me:

camera_info.DeviceInfo(end).DeviceID;
camera_info.DeviceInfo(end).SupportedFormats(end));

larry suide

i want to install this code on a dsp and as an output the coordinates of the tracked red. what is the fct to output them to the workspace?

SNAKE

SNAKE (view profile)

How can I extract the position of an object (red) , and store it???

good one,but how to interrupt it while the loop is on??? stop(vid) doesn't work until 200 frames are taken ,

Hi dude.. this tracking is awesome... But can u help me with some more processing like, reducing the brightness of the red colored object.

Arvin

Arvin (view profile)

how to detect any color other than white?

A. Bhargav Anand

the '-m+' is an argument given to the plot function. Just to display markers on the plot, we pass it as an argument. Here '-m+' refers to use the color magenta and display a 'plus' sign wherever required. You could do 'help plot' for further help. Thanks

Siddharth

Hey Bhargav, this code works really well, just a doubt though, what does '-m+' in the plot(bc(1),bc(2), '-m+') function mean?

amila perera

:( Guys..I got this error msg..What might be the problem..?

??? Error using ==> end
Incorrect cell or structure reference involving "end".
Most likely cause is a reference to multiple elements of a cell or
structure followed by additional subscript or structure references.

Error in ==> getCameraInfo at 4
camera_id = camera_info.DeviceInfo.DeviceID(end);

Error in ==> redObjectTrack at 2
[camera_name, camera_id, format] = getCameraInfo(a);

James

James (view profile)

Scratch what I said earlier, haha the numerical value can detect white and Blue, but not green or red or black. haven't tried all the colors but still, great job!

James

James (view profile)

Hi! I love your work!
I got curios and messed around with the codes, in this line..
diff_im = imsubtract(data(:,:,1), rgb2gray(data));

change the numerical value 1 to 2 and 3..
the value of 3 can detect color white. while value of 2, I couldn't detect anything.

can you tell me how to detect other colours?

or much better tell me where you learned this. thank you your work is awesome! keep it up! :)

Rod

Rod (view profile)

Gioridesky

arsalan sadiq

arsalan sadiq

dude can u plz tell me how to detect other colors also....

Chen Mr

pretty good!!

abu sadat

abu sadat

good

Thanks a lot mate,your prog has helped me a lot,keep doin your thing.

Fuat Cogun

maybe it could benefit me ,if you were to tell me where did you leant that.

Ajay Kumar

elias argaw

please help
i try your code but i got the below message how i can fix it

??? Undefined function or method 'getCameraInfo'
for input arguments of type 'struct'.

Great job. Thank you for sharing.

Peter Russo

Awesome, thanks a lot! I've been trying to make my own that uses just the intensity of the grayscale image, which is giving me lots of problems. By just picking a color, like red, it should be a lot easier. Thanks

Mr Smart

Mohamad Faiz

Hi dude, do you know how to track red color using IP camera?

Hi..Cud u pl tell me how to-
1) track colours other than red.
2) set the threshold such that the object in the front is tracked and not any other object in the back.
Thnx...

Boo

Boo (view profile)

dads PB

Hey Dude if you teach me create red light camera using M-file ? pleasee

atiqah

atiqah (view profile)

nishant

outstanding

alexander

i'm getting errors from the getcamerainfo function

Error in ==> getCameraInfo at 4
camera_id = camera_info.DeviceInfo.DeviceID(end);

Error in ==> redObjectTrack at 2
[camera_name, camera_id, format] = getCameraInfo(a);

running r2010a 64 bit in windows 7

how might i remedy these errors

Sujin Wanchat

Dude, my ML tells me that an error occurred " Error: File: redObjectTrack.m Line: 2 Column: 2
An array for multiple LHS assignment cannot contain character string." i think its related to the format of my camera : YCbCr422_640x480 does your program run with this format

hey please tell me to initialize webcam in MATLAB... im new in MATLAB.. what i have to write in your code to run it...
i thnk its cam name n resolution etc.. please give me example of correct syntax and where to read the name of camera and resolution...

Atif Anwer

Brilliant Job Done! Really helpful in using this as a start for my Vision project :)

I think it would be better if you use the conversion rgb to hsi, and determine the red color with hue, but it is a nice algorithm, and you help me a lot to know how to use my laptop camera.

I had this working like a dream on Windows (this is a wonderful piece of software), but it seems to have trouble on a Mac. The video doesn't move fluidly, but rather captures just a couple of frames. Does anyone have the same issues, or advice? I'm admittedly new to Mac... Thanks!

Arun

Arun (view profile)

The speed of your code can be greatly improved if u can keep preview open in background.Also try to replace getsnapshot with peekdata (dont know to what extent it is possible)to reduce execution time(this may require manual triggering)

Vladimir

A. Bhargav Anand

Thanks man :)

Hoa Dang

you are wonderful !!!
Thank you alot

chen po sen

very smart and good experimental , thks .

A. Bhargav Anand

Updated the code guys. Also uploaded a video.

http://www.youtube.com/watch?v=ARJae5d3oLg

A. Bhargav Anand

@hiren, ika- sorry guys, ive been little busy these dayz, neways ill definitly get back to you guys with an answer. As of now this program was written only to detect the standard colors i.e. Red, Green & Blue colors. I was thinking to extend the whole program by adding a graphical interface and generalizing the whole tracking process.

@akash- you get lotz of stuff on internet dude. juss google about object tracking or motion tracking. Look the documentation of the image processing & video processing toolbox in matlab. Use the matlab help and go through the documentation of important functions that will be helpful. Thas enough fr mastering fundas !!! :)

ika

ika (view profile)

can u tell me how to make tracking object if i want track motion object and give annotation from start point untilthe object stop moving,so i can track from fisrt position, for example tracking with line???

thanks before....

hiren

hiren (view profile)

hi dude can u tell me how i can detect other colour..
i mean where i can change the code so i can do that thing...
thanks...

hiren

hiren (view profile)

hiren

hiren (view profile)

A. Bhargav Anand

@akash Dude, download the code, I have documented the whole code. Just go through it, try reading the documentation of every function i have used. And yeah, where did I get this stuff, GOOGLE it man !!!

akash

akash (view profile)

wow!!really that was so simple.can u tell me where u learned this stuff.it will be really helpful

Updates

1.1

Previously the program just tracked the red object. Now the program has been updated to display the centroid of the detected object dynamically.

MATLAB Release
MATLAB 7.7 (R2008b)
Acknowledgements

Inspired: Virtual Painting, VideoStreamSURF

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video