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 (최근 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!