Detection and Tracking of Red Color Project report 2014 Name: ABHIRAJ BOHRA SEC: EC-A Roll no.: 110103005
[Type the document title] Detection and Tracking of RED color by Using MATLAB 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. % Capture the videoframesusingthe videoinputfunction % replace the resolution&yourinstalledadaptorname. % Setthe propertiesof the videoobject %start the videoaquisition %detectRED colourand Track Function CODE: function [camera_name, camera_id, resolution] = getCameraInfo(a) camera_name = char(a.InstalledAdaptors(end)); camera_info = imaqhwinfo(camera_name); camera_id = camera_info.DeviceInfo.DeviceID(end); resolution = char(camera_info.DeviceInfo.SupportedFormats(end));
Main CODE: a = imaqhwinfo; [camera_name, camera_id, format] = getCameraInfo(a); vid = videoinput(camera_name, camera_id, format); set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb') vid.FrameGrabInterval = 5; start(vid) while(vid.FramesAcquired<=200) data = getsnapshot(vid); diff_im = imsubtract(data(:,:,1), rgb2gray(data)); diff_im = medfilt2(diff_im, [3 3]); diff_im = im2bw(diff_im,0.18); diff_im = bwareaopen(diff_im,300); bw = bwlabel(diff_im, 8); stats = regionprops(bw, 'BoundingBox', 'Centroid'); imshow(data) hold on 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: ', num2str(round(bc(2))))); set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow'); end hold off end stop(vid); flushdata(vid); clear all

Detection and tracking of red color by using matlab

  • 1.
    Detection and Trackingof Red Color Project report 2014 Name: ABHIRAJ BOHRA SEC: EC-A Roll no.: 110103005
  • 2.
    [Type the documenttitle] Detection and Tracking of RED color by Using MATLAB 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. % Capture the videoframesusingthe videoinputfunction % replace the resolution&yourinstalledadaptorname. % Setthe propertiesof the videoobject %start the videoaquisition %detectRED colourand Track Function CODE: function [camera_name, camera_id, resolution] = getCameraInfo(a) camera_name = char(a.InstalledAdaptors(end)); camera_info = imaqhwinfo(camera_name); camera_id = camera_info.DeviceInfo.DeviceID(end); resolution = char(camera_info.DeviceInfo.SupportedFormats(end));
  • 3.
    Main CODE: a =imaqhwinfo; [camera_name, camera_id, format] = getCameraInfo(a); vid = videoinput(camera_name, camera_id, format); set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb') vid.FrameGrabInterval = 5; start(vid) while(vid.FramesAcquired<=200) data = getsnapshot(vid); diff_im = imsubtract(data(:,:,1), rgb2gray(data)); diff_im = medfilt2(diff_im, [3 3]); diff_im = im2bw(diff_im,0.18); diff_im = bwareaopen(diff_im,300); bw = bwlabel(diff_im, 8); stats = regionprops(bw, 'BoundingBox', 'Centroid'); imshow(data) hold on 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: ', num2str(round(bc(2))))); set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow'); end hold off end stop(vid); flushdata(vid); clear all