Drawing a bounding box around foreground objects
3 次查看(过去 30 天)
显示 更早的评论
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'));
采纳的回答
Image Analyst
2013-6-7
You probably need a "hold on" between these two lines:
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bco(1),bco(2),'-m+')
Like this:
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
hold on;
plot(bco(1),bco(2),'-m+')
更多回答(1 个)
Mohammedashraf Shaikh
2017-3-23
%%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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!