Why I get the background in white color while it should be black !
2 次查看(过去 30 天)
显示 更早的评论
Hi ..
I have the following code:
vid = videoinput('winvideo',1);
set(vid, 'ReturnedColorspace', 'rgb');
% set(vid,'FramesPerTrigger',4);
set(vid,'TriggerRepeat',Inf);
vid.FrameGrabInterval = 6;
start(vid);
BackgroundImage = getsnapshot(vid);
I1 = rgb2gray(BackgroundImage);
figure;
subplot(3,3,1);
imshow(I1);
title('Background F1');
while 1
frames = getsnapshot(vid);
subplot(3,3,2);
imshow(frames);
title('RGB frames');
I2 = rgb2gray(frames);
subplot(3,3,3);
imshow(I2);
title('Gray frames');
Objects = I1 ~= I2;
subplot(3,3,4);
imshow(Objects);
title('Objects');
end
In this part of code should give me a black background and the objects should be white
Objects = I1 ~= I2;
subplot(3,3,4);
imshow(Objects);
title('Objects');
but I get white background ! when I tried it on images it was work just fine :|
Could you please help me
0 个评论
采纳的回答
Image Analyst
2018-3-9
Every pixel is likely to be different since it came from a video camera. So you can't compare value for value. You should see if values are within some tolerance threshold, like closer than 5 gray levels or whatever.
toleranceThreshold = 5; % Whatever works for you...
Objects = abs(double(I1) - double(I2)) > toleranceThreshold; % A binary image.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!