Azzera filtri
Azzera filtri

Adding/Deleting draggable rectangles on the image

2 visualizzazioni (ultimi 30 giorni)
Naseer Khan
Naseer Khan il 20 Set 2016
Commentato: Adam il 20 Set 2016
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 Commento
Adam
Adam il 20 Set 2016
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su C4ISR in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by