Effacer les filtres
Effacer les filtres

Adding/Deleting draggable rectangles on the image

1 vue (au cours des 30 derniers jours)
Naseer Khan
Naseer Khan le 20 Sep 2016
Commenté : Adam le 20 Sep 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 commentaire
Adam
Adam le 20 Sep 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by