How can I save the frame on one loop to subtract it to another frame in the next loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
Okay so i want to subtract one frame from a video from the one who came before, so if the value is high enough i can tell that there's movement, the problem is that i have to use this base model, the reason why the image is binarized is so its easier to detect movement:
function hello(nameIn,nameOut)
vin = VideoReader(nameIn);
vout = VideoWriter(nameOut,'MPEG-4');
open(vout);
while hasFrame(vin)
frameIn = readFrame(vin);
imagesc(imdilate(frameIn,ones(5))-imerode(frameIn,ones(5)));axis equal
frameOut = (imdilate(frameIn,ones(5))-imerode(frameIn,ones(5)));
%ideally everything would be written here
writeVideo(vout,frameOut);
end
close(vout);
my idea was something similar to this:
function hello(nameIn,nameOut)
vin = VideoReader(nameIn);
vout = VideoWriter(nameOut,'MPEG-4');
open(vout);
while hasFrame(vin)
frameIn = readFrame(vin);
diference = frameIn - save;
if (diference < 100)
%printf the second this happens
end
frameOut = (imdilate(frameIn,ones(5))-imerode(frameIn,ones(5)));
save = frameOut;
writeVideo(vout,frameOut);
end
close(vout);
and as i expected, it goes horribly wrong, i dont really know how to solve this problem, if someone can help i would much appreciate it, thanks and sorry if this is a mess.
댓글 수: 0
답변 (1개)
Aishwarya
2023년 10월 13일
편집: Aishwarya
2023년 10월 13일
Hi Miquel,
After reviewing the code provided, I think the problem is in how the difference is calculated. In the code, this statement could be the reason for ambiguity:
diference = frameIn – save
“diference” variable is same dimension as “frameIn” image matrix and is not a numerical value. To address this, I suggest incorporating the following line instead:
diference = mean(frameIn – save)
By doing so, you will obtain the mean value of the pixel difference as required.
Regards,
Aishwarya
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!