matlab - How to change colour in Object Tracking -


this matlab example code arindam bose track red objects. have changed code little track objects video stream. track red objects camera.

http://www.mathworks.com/matlabcentral/fileexchange/28757-tracking-red-color-objects-using-matlab

however want track objects other colours green, black, white, etc, too. studying code can not see change colour information.

maybe line fo code responsible changing colour?

diffframe = imsubtract(rgbframe(:,:,1), rgb2gray(rgbframe)); % red component of image 

or

i have changed treshold, no success:

redthresh = 0.15; % threshold red detection 

but no idea how change oject colour green or other colour.

thanks suggestion.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % program name : red object detection , tracking % author : arindam bose % version : 1.05 % description : how detect , track red objects in live video %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% initialization redthresh = 0.15; % threshold red detection  %viddevice = imaq.videodevice('winvideo', 1, 'yuy2_640x480', ... % acquire input video stream %'roi', [1 1 640 480], ... %'returnedcolorspace', 'rgb');  vidinfo = videoreader('myvideo.avi'); videoresult = videowriter('c:\myproject\y_videos\resultvideo.avi');  % finales video mit koordinaten der roten blobs  open(videoresult); % Öffne finales video   % vidinfo = readframe(video); % acquire input video property  hblob = vision.blobanalysis('areaoutputport', false, ... % set blob analysis handling 'centroidoutputport', true, ... 'boundingboxoutputport', true', ... 'minimumblobarea', 10, ... 'maximumblobarea', 950, ... 'maximumcount', 30); hshapeinsredbox = vision.shapeinserter('bordercolor', 'custom', ... % set red box handling 'custombordercolor', [255 255 255], ... 'fill', true, ... 'fillcolor', 'custom', ... 'customfillcolor', [0 0 0], ... 'opacity', 0.3); htextins = vision.textinserter('text', 'red objects: %2d', ... % set text number of blobs 'location', [7 2], ... 'color', [255 255 255], ... // red color 'fontsize', 14); htextinscent = vision.textinserter('text', '+ x:%4d, y:%4d', ... % set text centroid 'locationsource', 'input port', ... 'color', [255 255 255], ... // white color 'fontsize', 14);  hvideoin = vision.videoplayer('name', 'final video', ... % output video player 'position', [100 100 610 500]); nframe = 0; % frame number initialization %% processing loop while(nframe < 500) rgbframe = readframe(vidinfo); %rgbframe = step(viddevice); % acquire single frame %rgbframe = flip(rgbframe,2); % obtain mirror image displaying diffframe = imsubtract(rgbframe(:,:,1), rgb2gray(rgbframe)); % red component of image diffframe = medfilt2(diffframe, [3 3]); % filter out noise using median filter binframe = im2bw(diffframe, redthresh); % convert image binary image red objects white [centroid, bbox] = step(hblob, binframe); % centroids , bounding boxes of blobs centroid = uint16(centroid); % convert centroids integer further steps rgbframe(1:20,1:165,:) = 100; % put black region on output stream vidin = step(hshapeinsredbox, rgbframe, bbox); % instert red box  object = 1:1:length(bbox(:,1)) % write corresponding centroids centx = centroid(object,1);  centy = centroid(object,2); vidin = step(htextinscent, vidin, [centx centy], [centx-6 centy-9]); end vidin = step(htextins, vidin, uint8(length(bbox(:,1)))); % count number of blobs step(hvideoin, vidin); % output video stream  writevideo(videoresult,vidin)  nframe = nframe+1; end  %% clearing memory release(hvideoin); % release memory , buffer used %% release(viddevice); %%clear all; close(videoresult);  clc; 

your guess correct. colour images n x m x 3 matrices, img(:,:,1) red channel, img(:,:,2) green one, , img(:,:,3) blue one.


Comments