Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Sanjeev
Posts:
4
Registered:
12/27/12
|
|
MATLAB Moving Object detction
Posted:
Jan 2, 2013 7:13 AM
|
|
Can any1 help me with my code? i cant get the moving object output to the real time input. I jst get a colored empty screen function realVideo() % Define frame rate NumberFrameDisplayPerSecond=25;
% Open figure hFigure=figure(1);
% Set-up webcam video input source= videoinput('winvideo'); % Set parameters for video Acquire only one frame each time set(source,'FramesPerTrigger',1); % Go on forever until stopped set(source,'TriggerRepeat',Inf); % Get a RGB image set(source,'ReturnedColorSpace','RGB'); triggerconfig(source, 'Manual'); % set up timer object TimerData=timer('TimerFcn', {@FrameRDisplay,source},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop'); % Start video and timer object start(source); start(TimerData);
% We go on until the figure is closed uiwait(hFigure); % Clean up everything stop(TimerData); delete(TimerData); stop(source); delete(source); % clear persistent variables clear functions; end
function FrameRDisplay(obj, event,source) persistent IM; trigger(source); IM=getdata(source,1,'uint8'); subplot(2,1,1); imagesc(IM); bg = getsnapshot(source(1)); % read in 1st frame as background frame bg_bw = rgb2gray(bg); % convert background to greyscale
% ----------------------- set frame size variables ----------------------- fr_size = size(bg); width = fr_size(2); height = fr_size(1); f = zeros(height, width); %f2 = zeros(height, width);
% --------------------- process frames -----------------------------------
for i = 2:3:(length(source)-1) fr1 = source(i-1).cdata; % read in frame-i-1 fr_bw1 = rgb2gray(fr1); % convert frame-i-1 to grayscale fr2 = source(i).cdata; % read in frame-i fr_bw2 = rgb2gray(fr2); % convert frame-i to grayscale fr3 = source(i+1).cdata; % read in frame-i+1 fr_bw3 = rgb2gray(fr3); % convert frame-i+1 to grayscale fr_diff1 = abs(double(fr_bw1) - double(fr_bw2)); % First frame Difference cast operands as double to avoid negative overflow fr_diff2 = abs(double(fr_bw2) - double(fr_bw3)); % Second frame difference cast operands as double to avoid negative overflow if ((fr_diff1(k,j) > thresh) && (fr_diff2(k,j) > thresh)) f(k,j) = 255; else f(k,j) = 0;
end end
subplot(2,1,2); imagesc(uint8(f)); title('MOVING OBJECT'); end
|
|
|
|