Matlab Object Detection Tracking

preview_player
Показать описание
Video showing, Tracking red color objects using matlab, original code written by: A. Bhargav Anand. We set up the web cam, then upload the file and made magic.
Рекомендации по теме
Комментарии
Автор

guys this is the code :
a = imaqhwinfo;
[camera_name, camera_id, format] = getCameraInfo(a);


% Capture the video frames using the videoinput function
% You have to replace the resolution & your installed adaptor name.
vid = videoinput(camera_name, camera_id, format);

% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;

%start the video aquisition here
start(vid)

% Set a loop that stop after 100 frames of aquisition

    
    % Get the snapshot of the current frame
    data = getsnapshot(vid);
    
    % Now to track red objects in real time
    % we have to subtract the red component 
    % from the grayscale image to extract the red components in the image.
    diff_im = imsubtract(data(:, :, 1), rgb2gray(data));
    %Use a median filter to filter out noise
    diff_im = medfilt2(diff_im, [3 3]);
    % Convert the resulting grayscale image into a binary image.
    diff_im = im2bw(diff_im, 0.18);
    
    % Remove all those pixels less than 300px
    diff_im = bwareaopen(diff_im, 300);
    
    % Label all the connected components in the image.
    bw = bwlabel(diff_im, 8);
    
    % Here we do the image blob analysis.
    % We get a set of properties for each labeled region.
    stats = regionprops(bw, 'BoundingBox', 'Centroid');
    
    % Display the image
    imshow(data)
    
    hold on
    
    %This is a loop to bound the red objects in a rectangular box.
    for object = 1:length(stats)
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;
        rectangle('Position', bb, 'EdgeColor', 'r', 'LineWidth', 2)
        plot(bc(1), bc(2), '-m+')
        a=text(bc(1)+15, bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ',
        set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
    end
    
    hold off
end
% Both the loops end here.

% Stop the video aquisition.
stop(vid);

% Flush all the image data stored in the memory buffer.
flushdata(vid);

% Clear all variables
clear all
sprintf('%s', 'That was all about Image tracking, Guess that was pretty easy :) ')
 

enjoy :=)

moussalamousse
Автор

thanks for the video man, i had gotten the code weeks ago but couldn't get it to work but now it does

jamrockpirate
Автор

Code related questions email A. Bhargav Anand, google "Tracking red color objects using matlab"
 

BadBlad
Автор

Hello .This helped me alot! Pretty simple and clear explanation! Thanks

chaithragowda
Автор

sooo nice!!! i have an other question for you! Do you know how we can track a shape with matlab?  at thie moment i learn the code for tracking blue objet we will see :)

Christojet
Автор

is necesarry just a webcam to do it ? thanks a lot dear.

shupinho
Автор

is there any way out to do this programming without an please let me know.... is dont have webcam attached to my pc.

soumakghosh
Автор

Thanks so very much! this is what I'd been looking for ;) Blessings

lalehhaidari
Автор

hi, can you help me? what is/are the code/s to display the word "red" if the red object has been detected? please help. your response will be much appreciated. thank you.

redlangga
Автор

thank u...Sir..And thank u..BHARGAV ANAND...!!
how could i make it very smooth ?? and is it depend on camera ??

Hetuh
Автор

Thanks man, nice video, nice explaining.

zerosiii
Автор

why is my figure window shows complete black colour when i run this code ? I am using laptop webcam

protikbiswas
Автор

thank you very much.Do you know detection face code?

natcomengineer
Автор

i typed but i cant generate a name.
is it because i was trying to us my laptop's camera?
is it a must to buy a camera?

cyxiu
Автор

Hi guys i wanna ask should i connect a usb camera or does the intergrated camera in my PC work ?
cause i had errors in this command a=imqhwinfo??

haythemhamdi
Автор

this can be applied to roulette to track the ball speed and to predict the winning number

rouletteplayer
Автор

What is the position of the origin ? And what are the units of the coordinates?

Celexa
Автор

Where to change if I wana make this code for detect and track any moving object not only red one

shiam
Автор

i want to use this code in robotics application to pickup the garbage of red color by the help of robot (green colored ) so plz help me that how can i take difference between the robot and garbage's coordinate and give the cammand to teh robot by the pc wireless by using RF module and one thing more, problem occured when we start tracking the device then after some time image window is paused automatically why?    

AkashSingh-omyg
Автор

thankyou for showing how to add external cam
it helped a lot
btw can you give me the idea how can i send only the details of y axis of the red object to arduino?

ishmeetbindra