Wait for user to draw rectangle

조회 수: 2 (최근 30일)
Mohamed Amine Henchir
Mohamed Amine Henchir 2018년 11월 1일
댓글: Mohamed Amine Henchir 2018년 12월 11일
would like to crop an image using drawrectangle, the thing is I want the user to be the one who ends the selection process that's why I thought about using waitfor but it didn't work so far, can you explain why? here is my code
if true
function select_roi_Callback(hObject, eventdata, handles)
% hObject handle to select_roi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
guidata(hObject, handles);
A = handles.I;
h = drawrectangle(handles.axes1);
waitfor(h);
I = imcrop(A,h.Position);
imshow(I);
handles.I = I;
guidata(handles.figure1,handles);
h = datacursormode;
set(h,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
end
thank you!

채택된 답변

Matt J
Matt J 2018년 11월 1일
편집: Matt J 2018년 11월 1일
If you use imrect instead, the code will pause until the user finalizes the rectangle selection by double-clicking.
h=imrect;
wait(h);
  댓글 수: 4
Carlos Castilla
Carlos Castilla 2018년 12월 3일
h1 = drawrectangle('Position', lPoints,'FixedAspectRatio',true);
while h1.Selected == 0
pause;
end
Mohamed Amine Henchir
Mohamed Amine Henchir 2018년 12월 11일
thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by