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?

7 vues (au cours des 30 derniers jours)
%%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 ');
  2 commentaires
komal
komal le 11 Juin 2019
thank you for the above code. I need to subtract frames from each other like frame1- frame 2 and frame2-frame3 and so on till videos end. Then want to display the each result of differences on the graph

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 4 Mai 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 commentaires
Mohammedashraf Shaikh
Mohammedashraf Shaikh le 5 Mai 2017
Modifié(e) : Image Analyst le 5 Mai 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 le 5 Mai 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by