[MATLAB] waitforbuttonpress (키보드를 눌러 그림을 넘길 경우)
MATLAB에서 대규모의 영상에 대해, 결과를 직접 눈으로 검토해야 할 경우가 있다.
예를 들어, 얼굴검출 결과를 본다거나, tone mapping 결과를 본다거나...
이때 보통 for문 안에서
pause 함수를 써서 몇초간 기다렸다가 다음 영상의 결과를 볼 수도 있지만
(pause(n) : pause for 5 seconds)
대부분의 결과 영상은 빨리 넘기고, 특정 영상은 자세히 관찰해야하는 경우와 같이
for문 안에서 그림을 넘기는 시점을 직접 제어해야 편리할 때가 있다.
이때는 waitforbuttonpress 함수를 써보자.
for i=1:N
% image processing
% algorithm
%
% 결과 display
figure;
imshow(I)
% 사용자가 버튼을 누를때, 다음 영상으로 이동
waitforbuttonpress;
end
MATLAB의 설명
WAITFORBUTTONPRESS Wait for key/buttonpress over figure.
T = WAITFORBUTTONPRESS stops program execution until a key or
mouse button is pressed over a figure window. Returns 0
when terminated by a mouse buttonpress, or 1 when terminated
by a keypress. Additional information about the terminating
event is available from the current figure.
Example:
f = figure;
disp('This will print immediately');
keydown = waitforbuttonpress;
if (keydown == 0)
disp('Mouse button was pressed');
else
disp('Key was pressed');
end
close(f);