필터 지우기
필터 지우기

Adding/Deleting draggable rectangles on the image

조회 수: 2 (최근 30일)
Naseer Khan
Naseer Khan 2016년 9월 20일
댓글: Adam 2016년 9월 20일
In the following code I am drawing number of rectangles on the Image and saving them to a file.My problem is that when I delete a rectangle(s) from the Image I get "Invalid or delete object" error.
I have created 3 buttons. "Load" load the Image "DrawRectangles" draw draggable rectangles on the Image "Save" saves all rectangles on the image to a file.
Load Button
% --- Executes on button press in loadButton.
function loadButton_Callback(hObject, eventdata, handles)
% hObject handle to loadButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=imread('http://ichef.bbci.co.uk/corporate2/images/width/live/p0/0l/3r/p00l3rnt.jpg/624');
imshow(I);
rectangles=cell(1,1);
count=0;
handles.rectangles=rectangles;
handles.count=count;
guidata(hObject,handles);
Draw Rectangle Button
function drawButton_Callback(hObject, eventdata, handles)
% hObject handle to drawButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rectangles=handles.rectangles;
count=handles.count;
count=count+1;
h=imrect;
rectangles{count,1}=h;
handles.count=count;
handles.rectangles=rectangles;
guidata(hObject,handles);
Save Button
function saveButton_Callback(hObject, eventdata, handles)
% hObject handle to saveButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rectangles=handles.rectangles;
for i=1:length(rectangles)
dlmwrite('P:\bla.txt',rectangles{i}.getPosition,'-append','delimiter',' ','newline','pc');
end
How to fix this error and please also tell me how would I change the color and pixel size of the draggable rectangles that are being drawn on the Image.
  댓글 수: 1
Adam
Adam 2016년 9월 20일
You don't seem to have any code there that is deleting a rectangle so I'm not quite sure what error you mean. Also please give the full erorr message rather than just a shortened interpretation of it, including showing which line causes the error.

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

답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by