Clear Filters
Clear Filters

After converting video into frame, and appling frame differencing method to subtract two image, now i want to draw boundary in foreground of video, how?

3 views (last 30 days)
%%Extracting & Saving of frames from a Video file through Matlab Code%%
clc;
close all;
clear all;
% assigning the name of sample mp4 file to a variable
filename = 'C:\Users\Hp\Desktop\xyz.mp4';
%reading a video file
mov = VideoReader(filename);
%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
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
%frame differncing 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 ');

Accepted Answer

Image Analyst
Image Analyst on 4 May 2017
Use rectangle() or plot() to put lines into the overlay. Use text() to put words/strings into the overlay. You might have to put "hold on" first though.
  3 Comments
Mohammedashraf Shaikh
Mohammedashraf Shaikh on 5 May 2017
Edited: Image Analyst on 5 May 2017
The above two images are subtracted and I obtained this subtracted image. Now I want to draw a rectangle on the video containing the boy. How do I get the coordinates or anything else?
Image Analyst
Image Analyst on 5 May 2017
Threshold it. Call bwareafilt() to extract the largest blob. Call bwlabel(), then call regionprops() and ask for the bounding box. Then call "hold on" and call rectangle() to place the bounding box on the video. See if you can do those steps. Here's a start
binaryImage = subtractedImage > 30;
binaryImage = bwareafilt(binaryImage, 1);
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'BoundingBox');
hold on;
hRect = rectangle('Position', props.BoundingBox);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!