Hi sorry im new to image processing. Need some explanation , which 2 video attachment should I use for this MATLAB code and which reference image i should use? thank you

조회 수: 1 (최근 30일)
clc;
close all;
inputvideo=vision.VideoFileReader('traffic.avi');%<<<<<<<<<<<<
vid1=vision.VideoPlayer;
while~isDone(inputvideo)
frame1=step(inputvideo);
step(vid1,frame1);
pause(0.005);
end
imwrite(frame1,'D:\referenceimage.jpg','jpg');%<<<<<<<<<<<<<<
release(inputvideo);
release(vid1);
referenceimage=imread('D:\referenceimage.jpg');<<<<<<<<<<<<
vid2=vision.VideoFileReader('Traffic.avi');%<<<<<<<<<<<<<
X=zeros(2,121);
Y=zeros(2,121);
Z=zeros;
for i=2:121
clc
frame=step(vid2);
frame2=((im2double(frame))-(im2double(referenceimage)));
frame1=im2bw(frame2,0.2);
[labelimage]=bwlabel(frame1);
stats=regionprops(labelimage,'basic');
BB=stats.BoundingBox;
X(i)=BB(1);
Y(i)=BB(2);
Dist=((X(i)-X(i-1))^2+(Y(i)-Y(i-1))^2)^(1/2);
Z(i)=Dist;
if(Dist>10&&Dist<20)
display('MEDIUM SPEED');
elseif(Dist<10)
display('SLOW SPEED');
else
display('FAST SPEED');
end
S=strel('disk',6);
frame3=imclose(frame1,S);
step(vid1,frame1);
pause(0.05);
end
M=median(Z);
Speed=(M)*(120/8);
release(vid1)

답변 (1개)

Walter Roberson
Walter Roberson 2023년 1월 19일
traffic.avi is supplied with the Image Processing Toolbox.
The code reads and displays the content of the avi. The last frame is written to a file and then the file is read back in. It is not clear why the code bothers to write to a file and read back when it could have just used the content of frame1
  댓글 수: 4
Amirullah Bin Abdul Razak
Amirullah Bin Abdul Razak 2023년 1월 22일
Hi ,
Should I just delete off these two lines of just leave as it is from the program code? ''
imwrite(frame1,'D:\referenceimage.jpg','jpg');%<<<<<<<<<<<<<<
release(inputvideo);
release(vid1);
referenceimage=imread('D:\referenceimage.jpg');<<<<<<<<<<<<
vid2=vision.VideoFileReader('Traffic.avi');%<<<<<<<<<<<<<
X=zeros(2,121);
Y=zeros(2,121);
Z=zeros;
for i=2:121
clc
frame=step(vid2);
frame2=((im2double(frame))-(im2double(referenceimage)));
Walter Roberson
Walter Roberson 2023년 1월 22일
FramesToProcess = 121; %don't ask me why
videoname = 'traffic.avi';
inputvideo = VideoReader(videoname);
vid1 = vision.VideoPlayer;
while hasFrame(inputvideo)
frame1 = readFrame(inputvideo);
step(vid1,frame1);
pause(0.005);
end
referenceimage = frame1;
inputvideo.CurrentTime = 0; %reset to beginning instead of release and reopen
vidlength = inputvideo.NumFrames;
if vidlength < FramesToProcess
clear inputvideo
error('video only has %d frames, need %d', vidlength, FramesToProcess);
end
X = zeros(2,FramesToProcess);
Y = zeros(2,FramesToProcess);
Z=zeros;
for i = 2:FramesToProcess
frame = read(inputvideo, i);
frame2=((im2double(frame))-(im2double(referenceimage)));
frame1=im2bw(frame2,0.2);
[labelimage]=bwlabel(frame1);
stats=regionprops(labelimage,'basic');
BB=stats.BoundingBox;
X(i)=BB(1);
Y(i)=BB(2);
Dist=((X(i)-X(i-1))^2+(Y(i)-Y(i-1))^2)^(1/2);
Z(i)=Dist;
if(Dist>10&&Dist<20)
display('MEDIUM SPEED');
elseif(Dist<10)
display('SLOW SPEED');
else
display('FAST SPEED');
end
S=strel('disk',6);
frame3=imclose(frame1,S);
step(vid1, frame3); %not frame1 !
pause(0.05);
end
M=median(Z);
Speed=(M)*(120/8);
release(vid1)
clear inputvideo

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by