How can fix the position of Edit box with bounding box in matlab

1 view (last 30 days)
I am dealing with face detection and recognition and I am getting bounding box around the face. now I want to add Edit box at the bottom of bounding box displaying name. I am using this command
set(handles.result,'String','Unknown Person','units','pix','position',[bbox(1) bbox(2) 200 30]);
but it is not as I desire and also it is not fixed . in each frame it moves separately from the bounding box. Please guide me in this regard. Thnaks

Answers (2)

Joseph Cheng
Joseph Cheng on 27 Aug 2014
Some questions come to mind about your bounding box. is the bbox(1) and bbox(2) points relative to the axis handle or relative to the frame? Such as is the NxN frame around person's face centered on image pixel location (512,456). The edit box position would be in relation to the bottom left corner of the GUI window so the pixel positioning of the image wouldn't match.
  1 Comment
Joseph Cheng
Joseph Cheng on 27 Aug 2014
I've expanded it to a single test script to give an example of positioning of the edit box.
I = imread('circuit.tif');
figure,
figH = axes;
set(figH,'units','pixel')
imagesc(I),colormap gray;
bbox =[20 40 50 100]; %generate where the box is
rectangle('Position',bbox,'linewidth',5,'edgecolor','r') %draw box
AXPos = get(figH,'Position'); %get Axis position
[row col] =size(I); %find image size
Posscale = [AXPos(3)/col AXPos(4)/row]; %find axis size to image pixel ratio
bboxLLC = [bbox(1) row-(bbox(2)+bbox(4))] %calc lower left corner (LLC) of bounding box (0,0) of image is Upper left corner.
editpos = [AXPos(1:2)+bboxLLC.*Posscale 200 30]; %calc position of edit box based on axis LLC.
uicontrol('style','edit','String','unkown person','Position',editpos);

Sign in to comment.


Image Analyst
Image Analyst on 27 Aug 2014
Why not simply use the text() function instead()? That would be so easy.

Community Treasure Hunt

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

Start Hunting!