function record = annotateobj(img, bbox, rltfile)

hh = figure;
[Y X N] = size(img);
imagesc(img);
rectangle('Position', [bbox(1), bbox(2), bbox(3)-bbox(1), bbox(4)-bbox(2)], ...
    'EdgeColor', 'r', 'LineWidth', 2);
set(gca, 'Units', 'pixels');

handles = [];
texthandles = [];
scenehandle = text(10, 15, '', 'FontSize', 15, 'Color', 'c');
numobjects = 0;
boolmoreobjects = 1;

while boolmoreobjects == 1
    [x, y, but] = ginput(1);
    switch lower(char(but))
        case {1, 2, 3}
            numobjects = numobjects + 1;
            p1 = get(gca, 'CurrentPoint');
            fr = rbbox;
            p2 = get(gca, 'CurrentPoint');
            p = round([p1; p2]);
            xmin = min(p(:, 1));
            xmax = max(p(:, 1));
            ymin = min(p(:, 2));
            ymax = max(p(:, 2));
            record.bbox(numobjects, :) = [-1 xmin ymin xmax ymax];
            handles(numobjects) = drawbox(record.bbox(numobjects, 2:5));
            texthandles(numobjects) = text(record.bbox(numobjects, 2), ...
                record.bbox(numobjects, 3), '', 'FontSize', 15, 'Color', 'c');
        case 49
            record.bbox(numobjects, 1) = 1;
            set(texthandles(numobjects), 'string', 'ID = 1');
        case 50
            record.bbox(numobjects, 1) = 2;
            set(texthandles(numobjects), 'string', 'ID = 2');
        case 51
            record.bbox(numobjects, 1) = 3;
            set(texthandles(numobjects), 'string', 'ID = 3');
        case 52
            record.bbox(numobjects, 1) = 4;
            set(texthandles(numobjects), 'string', 'ID = 4');
        case {73, 105}
            record.scene = 'indoor';
            set(scenehandle, 'string', 'Indoor action');
        case {79, 111}
            record.scene = 'outdoor';
            set(scenehandle, 'string', 'Outdoor action');
        case 27
            if numobjects > 0
                set(handles(numobjects), 'Visible', 'off');
                set(texthandles(numobjects), 'Visible', 'off');
                numobjects = numobjects - 1;
            end
        case 32
            boolmoreobjects = 0;
    end
end

print(hh, '-dbmp', rltfile);
close(hh);
record.numobjects = numobjects;
if numobjects > 0
    record.bbox = record.bbox(1 : numobjects, :);
end


function h = drawbox(pts)
h = line(pts([1 3 3 1 1]), pts([2 2 4 4 2]), 'Color', 'm', 'LineWidth', 1);