필터 지우기
필터 지우기

Sir could i trouble you in asking for your help to look into my code and give a reason to why i dont get my needed output?

조회 수: 1 (최근 30일)
I'm doing my final year project on MOVING OBJECT DETECTION and with all the help from the internet finally finished my code and i jst wont get the Moving Object output. The video I'm feeding is a live video through my webcam.
function realVideo() NumberFrameDisplayPerSecond=10; hFigure=figure(1); source= videoinput('winvideo', 1); set(source,'FramesPerTrigger',1); set(source,'TriggerRepeat',Inf); set(source,'ReturnedColorSpace','RGB'); triggerconfig(source, 'Manual'); Timer=timer('TimerFcn', {@FrameRDisplay,source},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop'); start(source); start(Timer); uiwait(hFigure); stop(Timer); delete(Timer); stop(source); delete(source); clear functions; end
% This function is called by the timer to display one frame of the figure
function FrameRDisplay(obj, event,source) persistent IM; persistent handlesRaw; persistent handlesPlot;
trigger(source); IM=getdata(source);
if isempty(handlesRaw)
subplot(2,1,1);
imagesc(IM);
title('REAL TIME IMAGE');
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
for j=1:width % if fr_diff > thresh pixel in foreground
for k=1:height
if ((fr_diff1(k,j) > thresh) && (fr_diff2(k,j) > thresh))
f(k,j) = 255;
else
f(k,j) = 0;
end
end
end
subplot(2,1,2);
handlesPlot=imshow(uint8(f));
title('MOVING OBJECT');
end
end
end
  댓글 수: 12
Walter Roberson
Walter Roberson 2013년 1월 5일
"source" is the video object. length(source) is 1.
It is like having a clock and asking how many clocks you have (one!) when what you should have done is looked at the clock instead of counting how many there are. getdata(source) is the way to read the video instead of counting how many cameras you have.
Jerome Lecoq
Jerome Lecoq 2013년 1월 5일
편집: Jerome Lecoq 2013년 1월 5일
Hello Walter,
I am happy to modify my code at http://www.matlabtips.com/realtime-processing/ if you believe it is broken in any way. I never expected so many people to read it when I initially did it and I don't want anyone to rely on broken things.
The original code is somehow different from the version that Sanjeev made.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by