Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
i dont get an output for this using a GUI and a toggle button. Whats wrong?
조회 수: 1 (최근 30일)
이전 댓글 표시
clc;
source= videoinput('winvideo');
set(source, 'ReturnedColorSpace', 'RGB');
set(source, 'FramesPerTrigger', 1);
set(source, 'TriggerRepeat', inf);
triggerconfig(source, 'manual');
if get(handles.startstop,'Value')
start(source);
thresh = 15/255;
pause(2);
trigger(source);
bg = getdata(source,1,'double');
bg=bg(:,:,:,1);
bg_bw = rgb2gray(bg);
set(handles.startstop,'String','Stop');
set(handles.startstop,'Value',1);
handles.source = source;
guidata(gcbo, handles);
drawnow();
fr_size = size(bg);
width = fr_size(2);
height = fr_size(1);
f = zeros(height, width);
else
set(handles.startstop,'String','Start');
set(handles.startstop,'Value',0);
source = handles.source;
stop(source);
handles.source = [];
guidata(gcbo, handles)
end
while(get(handles.startstop,'Value'));
trigger(source);
fr = getdata(source,3,'double');
fr1=fr(:,:,:,1);
fr_bw1 = rgb2gray(fr1);
trigger(source);
fr2=fr(:,:,:,2);
fr_bw2 = rgb2gray(fr2);
trigger(source);
fr3=fr(:,:,:,3); % read in frame-i+1
fr_bw3 = rgb2gray(fr3); % convert frame-i+1 to grayscale
fr_diff1 = abs((fr_bw1) - (fr_bw2)); % First frame Difference cast operands as double to avoid negative overflow
fr_diff2 = abs((fr_bw2) - (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(1,2,1); imshow(fr1); title('REAL TIME VIDEO');
subplot(1,2,2); imshow(uint8(f)); title('DETECTED MOVING OBJECT'); bg_bw=fr_bw1;
end
댓글 수: 0
답변 (1개)
Jan
2013년 1월 31일
Please explain the occurring problem with any detail: Do you get an infinite loop, an error message, is the code too slow or does the figure disappear before you can see it?
The debugger can help you to find out, what happens: Set a breakpoint in the code and step through the program line by line.
Btw., you can omit the double FOR loop:
f = 255 * ((fr_diff1 > thresh) & (fr_diff2 > thresh));
댓글 수: 6
Image Analyst
2013년 1월 31일
Don't double space all your code after you paste it in. That is not necessary to get it to show up with one line of code per statement. Simply make sure there is a blank line before it, then highlight it all and click {}Code.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!