how to remove shadows from real time video
Mostra commenti meno recenti
hai this is code to detect moving object detection from real time video in RGB colour format.but the shadow is detecting as moving object how can i remove shadow from video.please help me and i have attached the paper which shows how to remove shadows.and the update_background function is given below.
clc;
clear all
close all;
vid = mmreader('hall_monitor.mpg'); Nframe = vid.NumberOfFrames;
L = 5;
%%WEBCAM
delete(imaqfind)
% vid=videoinput('winvideo',1,'YUY2_320x240');
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1 );
set(vid,'TriggerRepeat', Inf);
% start(vid);
% vid = videoinput('winvideo',1);
% View the default color space used for the data — The value of the ReturnedColorSpace property indicates the color space of the image data.
color_spec=vid.ReturnedColorSpace;
% Modify the color space used for the data — To change the color space of the returned image data, set the value of the ReturnedColorSpace property.
if ~strcmp(color_spec,'rgb')
set(vid,'ReturnedColorSpace','rgb');
end
start(vid)
pause
%%Detect background
trigger(vid);
im=getdata(vid,1); % Get the frame in im
[nr nc nm ] = size(im);
nf = L;
frames = zeros(nr,nc,nm,L);
for ii = 1:L
% ii;
trigger(vid);
im=getdata(vid,1);% Get the frame in im
% im=rgb2hsv(im);
% figure, imshow(im);
G = fspecial('gaussian',[9 9],2);
%# Filter it
im = imfilter(im,G,'same');
% end
% figure,imshow(im)
frames(:,:,:,ii) = im;
end
% BG =updateBG( frames);
BG = update_background(frames);
% raj=BG(:,:,1);
% toc
% clear frames
subplot(231)
imshow(uint8(BG))
title('BACKGROUND')
T=5;
%%Moving object Detection
for ii = 1:150
tic
trigger(vid);
im=getdata(vid,1); % Get the frame in im
% im=rgb2hsv(im);
G = fspecial('gaussian',[9 9],2);
%# Filter it
im = imfilter(im,G,'same');
% subplot(131)
subplot(232)
imshow(im)
title(['Frame = ' num2str(ii)])
diff = abs(BG-double(im));
diff = max(diff,[],3);
subplot(233)
imshow(diff,[]);
title('difference image')
bw = (diff>30);
bw = bwmorph(bw,'dilate');
% bw = bwmorph(bw,'open');
bw = bwareaopen(bw,600);
bw = bwmorph(bw,'dilate',6);
bw = bwmorph(bw,'close',6);
subplot(234)
imshow(bw);
title('segmented object')
bw = bwareaopen(bw,600);
subplot(235)
imshow(bw);
title('required object')
end
function BG = update_background(frames) % This program updates background by taking median of all frames [nr,nc,nm,nf] = size(frames); frames = double(frames); BG = zeros(nr,nc,nm); tic R1 = frames(:,:,1,:); G1 = frames(:,:,2,:); B1 = frames(:,:,3,:); BG(:,:,1) = median(R1,4); BG(:,:,2) = median(G1,4); BG(:,:,3) = median(B1,4);
Risposte (1)
Ahmed Swidan
il 23 Apr 2015
0 voti
This is spam he is adding "clear all"... Please remove this
2 Commenti
Michael Haderlein
il 23 Apr 2015
You are starting your career in this forum by accusing someone to spam, just for the reason that his code containing a command which is often used in the context of scripts?
Walter Roberson
il 28 Gen 2016
There was a recent posting in which a student indicated that in their class they were required to start their scripts with
clc
clear all
close all
As much as we dislike it, you can't really blame a student for doing what they are ordered to do if they want to pass the assignment.
Categorie
Scopri di più su Video Formats and Interfaces in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!