Borrar filtros
Borrar filtros

Adding/Deleting draggable rectangles on the image

2 visualizaciones (últimos 30 días)
Naseer Khan
Naseer Khan el 20 de Sept. de 2016
Comentada: Adam el 20 de Sept. de 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 comentario
Adam
Adam el 20 de Sept. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre C4ISR en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by