2016-08-04 3 views
0

表示されている画像から矩形座標を取得したいと思います。画像を前後に移動したいここに私のmatlabのGUIがあります。
enter image description here正しいMatlab 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

'imrect'のために別のボタンを作成してください... – excaza

答えて

0

少数の通知でプログラムを停止させてはいけない方法:

  • 私はベストプラクティスがExcazaが述べたように、別のボタンにimrectを移動させることだと思います。
  • 私はGUIサンプルを作成し、imrectが実行された後、すべてのボタンが反応して問題を繰り返すことができませんでした。
  • 「h =直筆;」の代わりに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...'); 
関連する問題