Help needed to write a rectangle bounding box on an image ...

3 次查看(过去 30 天)
hey everyone I'm working on a project using image processing and in the final step i need to draw a rectangle bounding box around an object and write a number in it.. i was able to imshow to display the image then used the rectangle command to draw the box.. my problem now is how to save the box on the image and how to write the number inside the box .. :(
thanks in advance :)

采纳的回答

Ben11
Ben11 2014-7-8
You can use "getframe" to get the image currently displayed in your figure/axes, hence it would save your image with the box.
Before doing that you can use a text annotation to place text inside your box by playing around with the coordinates of the text and then save your image.
doc getframe
doc text
If you need more details please ask.
  2 个评论
Alaa-eddean hussein
Thanks a lot Ben that is exactly what i needed
i was wondering if you know how to play a video in GUI , because i need to play the processed video in GUI
Ben11
Ben11 2014-7-9
编辑:Ben11 2014-7-9
Yep; there are a few ways you can play a video in a GUI. The one I use works well but others might do better. Basically you need an axis in which you "put your movie and a pushbutton which you press to stop/resume it. I based by code on an example by The Mathworks in which we make a globe spin.:
In my case, frames are in a cell array and I use imshow in a while loop to display them in the axis.
1) First I set a string array in the Play/Stop pushbutton CreateFcn which will be used when you press the play/stop pushbutton:
% --- Executes during object creation, after setting all properties.
function pushbutton29_Play_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton29_Play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
handles.PlayStrings = {'Play';'Stop'};
% Commit the new struct element to appdata
guidata(hObject, handles);
So each time you press the button, matlab will look at whether the string is play or stop and beave accordingly.
2) The code in the play/stop pushbutton callback looks like this, you can arrange it to fit your needs:
str = get(hObject,'String'); % get the current pushbutton string, i.e. "Play" or "Stop"
% Determine which string the label matches
state = find(strcmp(str,handles.PlayStrings));
% Toggle the button label to other string
set(hObject,'String',handles.PlayStrings{3-state});
Check the "state", i.e. the string displayed in the pushbutton.
if state ~= 1
return
elseif (state == 1)
axes(handlesToYourAxis) % make the axis current
mov(1:NumberOfFrames) = struct('cdata', [],'colormap', []);
for k=1:NumberOfFrames
mov(k).cdata = (CellArrayWithYouFrames{k}); %load data converted to 8bit
end % Create a movie structure with your frames in it. Might not be necessary for you, but it is for me :)
while ishandle(handlesToYourAxis) % Dummy condition allowing the while loop to run until you press the stop button.
imshow(mov(CurrentFrame).cdata,'Parent',handlesToYourAxis);
% If button label changed since last iteration, stop now
if find(strcmp(get(hObject,'String'),handles.PlayStrings)) == 1
break
end
end
That's about it; sorry for the formatting!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by