Drawing a bounding box around foreground objects
Mostrar comentarios más antiguos
Hello Everyone.
I have applied a backgrund subtraction algorithm called frame differencing it is working very well I can easily detect the moving objects from the video now I want to draw the rectanlge or bounding boc around the detected objects.I have used the connected component labelling here like that below provided by Image Analyst.But I could not draw the bounding box..Any help is appreciated.
figure(3);imshow(fg1);
drawnow;
hold on;
labeledImage = bwconncomp(fg1,8);
measurements = regionprops(labeledImage,'BoundingBox','Centroid');
if length(measurements) == 0
% No blobs found.
fprintf('Done!\n');
continue; % Skip to the next frame.
end
totalNumberOfBlobs = length(measurements);
for blobNumber = 1:totalNumberOfBlobs
bb = measurements(blobNumber).BoundingBox;
bco = measurements(blobNumber).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bco(1),bco(2),'-m+')
myCaption = sprintf('(x=%.1f, y=%.1f)', bco(1), bco(2));
text(bco(1)+15,bco(2), myCaption,...
'FontName','Arial','FontWeight','normal',...
'FontSize',12,'Color','blue');
set(gca,'xdir','normal')
set(gca,'ydir','reverse')
axis on;
end
drawnow; % Force display to update.
fprintf('Done!\n');
end
end
hold off
toc
uiwait(msgbox('Execution Ended'));
6 comentarios
muthu A
el 16 de Feb. de 2017
Hai , i am a beginner of matlab.I want matlab code for object detection using backgtround subtraction.i have extract frames from video.now i want to detect object from those frames.pls let u know those who have code for this..
Image Analyst
el 16 de Feb. de 2017
muthu, start a brand new question on this and attach two of the frames.
Mohammedashraf Shaikh
el 23 de Mzo. de 2017
%%Extracting & Saving of frames from a Video file through Matlab Code%% clc; close all; clear all;
% assigning the name of sample avi file to a variable filename = 'C:\Users\Hp\Desktop\xyz.mp4';
%reading a video file mov = VideoReader(filename);
% Defining Output folder as 'snaps' %opFolder = fullfile(cd, 'SEM-8'); %if not existing %if ~exist(opFolder, 'dir') %make directory & execute as indicated in opfolder variable %mkdir('C:\Users\Hp\Desktop\opFolder'); %end
%getting no of frames numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames for t = 1 : numFrames currFrame = read(mov, t); %reading individual frames opBaseFileName = sprintf('%3.3d.png', t); opFullFileName = fullfile('C:\Users\Hp\Desktop\col1', opBaseFileName); imwrite(currFrame, opFullFileName, 'png'); %saving as 'png' file %indicating the current progress of the file/frame written progIndication = sprintf('Wrote frame %4d of %d.', t, numFrames); disp(progIndication); numFramesWritten = numFramesWritten + 1; end %end of 'for' loop progIndication = sprintf('Wrote %d frames to folder "%s"',numFramesWritten, 'C:\Users\Hp\Desktop\col1'); disp(progIndication); %End of the code I=imread('C:\Users\Hp\Desktop\col\001.png'); I1=rgb2gray(I); imshow(I1); J=imread('C:\Users\Hp\Desktop\col1\001.png');
I1=rgb2gray(I); J1=rgb2gray(J);
imshow(I1); imshow(J1); K=I1-J1; figure; imshow(K); title('SUBTRACTED IMAGE ');
*TILL Now i had this which subtracting two image AND getting foreground By using my code how could i draw Boundary
*by this you can divide video into frame and compare new frame generated to some previous image using subtraction method
but i am not able to draw boundary in video or raise alarm pldease help me if you get *
Image Analyst
el 23 de Mzo. de 2017
Simply put hold on, then draw using plot() or rectangle(), then call drawnow.
Mohammedashraf Shaikh
el 25 de Mzo. de 2017
how to use hold on,plot or rectangle please help me out
Image Analyst
el 25 de Mzo. de 2017
hold on;
rectangle(.......whatever, or
plot(............ whatever.
Respuesta aceptada
Más respuestas (1)
Mohammedashraf Shaikh
el 23 de Mzo. de 2017
0 votos
%%Extracting & Saving of frames from a Video file through Matlab Code%% clc; close all; clear all;
% assigning the name of sample avi file to a variable filename = 'C:\Users\Hp\Desktop\xyz.mp4';
%reading a video file mov = VideoReader(filename);
% Defining Output folder as 'snaps' %opFolder = fullfile(cd, 'SEM-8'); %if not existing %if ~exist(opFolder, 'dir') %make directory & execute as indicated in opfolder variable %mkdir('C:\Users\Hp\Desktop\opFolder'); %end
%getting no of frames numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames for t = 1 : numFrames currFrame = read(mov, t); %reading individual frames opBaseFileName = sprintf('%3.3d.png', t); opFullFileName = fullfile('C:\Users\Hp\Desktop\col1', opBaseFileName); imwrite(currFrame, opFullFileName, 'png'); %saving as 'png' file %indicating the current progress of the file/frame written progIndication = sprintf('Wrote frame %4d of %d.', t, numFrames); disp(progIndication); numFramesWritten = numFramesWritten + 1; end %end of 'for' loop progIndication = sprintf('Wrote %d frames to folder "%s"',numFramesWritten, 'C:\Users\Hp\Desktop\col1'); disp(progIndication); %End of the code I=imread('C:\Users\Hp\Desktop\col\001.png'); I1=rgb2gray(I); imshow(I1); J=imread('C:\Users\Hp\Desktop\col1\001.png');
I1=rgb2gray(I); J1=rgb2gray(J);
imshow(I1); imshow(J1); K=I1-J1; figure; imshow(K); title('SUBTRACTED IMAGE ');
*TILL Now i had this which subtracting two image AND getting foreground By using my code how could i draw Boundary
Categorías
Más información sobre Video Formats and Interfaces en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!