2016-08-04 2 views
0

표시되는 이미지에서 직사각형 좌표를 가져 오려고합니다. 다음과 뒤로 이미지를 이동하고 싶습니다. 여기에 내 MATLAB GUI입니다.
enter image description hereMatlab GUI를 수정하지 않으려면 어떻게해야합니까?

그래서 다음을 누르면 일련의 다음 이미지가 표시되고 뒤로 가기 버튼이 표시됩니다. 이 코드

function next_Callback(hObject, eventdata, handles) 
% hObject handle to next (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
if handles.mypointer~=length(handles.cur_images) 
    handles.mypointer=handles.mypointer+1; 
    pic=imread(fullfile('images',handles.cur_images(handles.mypointer).name)); 
    handles.imageName=handles.cur_images(handles.mypointer).name; 
    imshow(pic); 
    h=imrect; 
    getMyPos(getPosition(h)); 
    addNewPositionCallback(h,@(p) getMyPos(p)); 
    fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim')); 
    setPositionConstraintFcn(h,fcn); 
    handles.output = hObject; 
    handles.posi=getPosition(h); 
    guidata(hObject, handles); 

그러나이 코드의 단점은 다음 버튼이 다음을 누를 때 너무 사각형을 그립니다 사용자를 기다리고 h=imrect에 중지한다는 것입니다을 사용하고 있습니다. 직사각형을 그리지 않으면 아무 일도하지 않습니다. 뒤로 또는 다음 단추를 다시 눌러도 사용자가 사각형을 그릴 때까지 기다리고 있기 때문에 아무 것도하지 않습니다. 그것은 명백한 질문이지만 나는 matlab에 GUI를 처음 접한다면 미안하다.
질문 :
방법 Imrect

+0

'바로 가기'버튼을 별도로 만듭니다 ... – excaza

답변

0

거의 고지에 프로그램 정지를 못하게 할 수는 :

  • 나는 가장 좋은 방법은 Excaza 언급처럼, 버튼을 분리 imrect을 이동하는 것입니다 생각합니다.
  • 난 당신의 문제를 반복하지 못했습니다 - 나는 GUI 샘플을 만들었고 모든 버튼은 imrect이 실행 된 후에 반응합니다.
  • 또한 'h = imrect;'대신 h = imrect(handles.axes1);을 실행하는 것이 좋습니다 (문제와 관련이 있는지 알 수 없음).

"차단 기능"Matlab에 문제가있을 때 타이머 개체의 콜백 함수에서 함수를 실행하여 문제를 해결했습니다.
좋은 연습인지 모르겠지만, 그게 해결 방법 일뿐입니다 ...
타이머 콜백 내부에서 함수를 실행하면 기본 프로그램 흐름을 계속 실행할 수 있습니다.

다음 코드 샘플은 타이머 개체를 만들고 타이머의 콜백 함수 내에 imrect을 실행하는 방법을 보여줍니다.
샘플은 "SingleShot"타이머를 만들고, start 함수를 실행 한 후 콜백이 200msec 실행되도록 트리거합니다.

function timerFcn_Callback(mTimer, ~) 
handles = mTimer.UserData; 
h = imrect(handles.axes1); %Call imrect(handles.axes1) instead just imrect. 
% getMyPos(getPosition(h)); 
% ... 

%Stop and delete the timer (this is not a goot practice to delete timer here - this is just an exampe). 
stop(mTimer); 
delete(mTimer); 


function next_Callback(hObject, eventdata, handles) 
% if handles.mypointer~=length(handles.cur_images) 
% ... 
% h = imrect(handles.axes1); 

%Create new "Single Shot" timer (note: it is not a good practice to create new timer each time next_Callback is executed). 
t = timer; 
t.TimerFcn = @timerFcn_Callback; %Set timer callback function 
t.ExecutionMode = 'singleShot'; %Set mode to "singleShot" - execute TimerFcn only once. 
t.StartDelay = 0.2;    %Wait 200msec from start(t) to executing timerFcn_Callback. 
t.UserData = handles;   %Set UserData to handles - passing handles structure to the timer. 

%Start timer (function timerFcn_Callback will be executed 200msec after calling start(t)). 
start(t); 

disp('Continue execution...'); 
관련 문제