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 次查看(过去 30 天)
显示 更早的评论
%%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 个评论
komal
2019-6-11
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
采纳的回答
Image Analyst
2017-5-4
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 个评论
Image Analyst
2017-5-5
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);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!