I am trying to detect potatoes on roller belt. I have created mean background from empty belt images and want to subtract it from each frame of the video and play back but not sure how to achieve this.

In other words, I would like to do something like this, but with each frame of the video:

>> Z = imread('mean.jpg');
>> X = imread('beltpotatoes_1.jpg'); 
>> C = Z - X;
>> imshow(C);

My sample data:

Mean background (mean.jpg): https://drive.google.com/file/d/0B_M7fjkKw1r3d0o3VHg1dXVFNmc/edit?usp=sharing

avi file: https://drive.google.com/file/d/0B_M7fjkKw1r3a3lhdl91bGFLSjQ/edit?usp=sharing

belt with potatoes image (beltpotatoes_1.jpg): https://drive.google.com/file/d/0B_M7fjkKw1r3SURDV19ud1VBQjQ/edit?usp=sharing

有帮助吗?

解决方案

Z = imread('mean.jpg');
VR=VideoReader('Video.avi');
NumInFrames=get(VR,'NumberOfFrames');

VW = VideoWriter('new.avi');
open(VW);

for (frame=1:NumInFrames)
    CDatas(:,:,:)=read(VR,frame) - Z;     
    writeVideo(VW,CDatas);   
end
close(VW)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top