function record = annotatepts(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);
h = text(10, 15, '0: Head top', 'FontSize', 15, 'Color', 'r');
set(gca,'Units','pixels');
record = -1 .* ones(16, 2);

curr_id = 1;
head = line([0 0], [0 0], 'Color', 'r', 'LineWidth', 2, 'Visible', 'off');
torso = line([0 0], [0 0], 'Color', 'g', 'LineWidth', 2, 'Visible', 'off');
left_upper_arm = line([0 0], [0 0], 'Color', 'b', 'LineWidth', 2, 'Visible', 'off');
left_lower_arm = line([0 0], [0 0], 'Color', 'c', 'LineWidth', 2, 'Visible', 'off');
right_upper_arm = line([0 0], [0 0], 'Color', 'b', 'LineWidth', 2, 'Visible', 'off');
right_lower_arm = line([0 0], [0 0], 'Color', 'c', 'LineWidth', 2, 'Visible', 'off');
left_upper_leg = line([0 0], [0 0], 'Color', 'm', 'LineWidth', 2, 'Visible', 'off');
left_lower_leg = line([0 0], [0 0], 'Color', 'y', 'LineWidth', 2, 'Visible', 'off');
right_upper_leg = line([0 0], [0 0], 'Color', 'm', 'LineWidth', 2, 'Visible', 'off');
right_lower_leg = line([0 0], [0 0], 'Color', 'y', 'LineWidth', 2, 'Visible', 'off');
flag = 1;
while flag
    [x, y, button] = ginput(1);
    
    switch button
        case 1  % press left key
            record(curr_id, 1) = round(x);
            record(curr_id, 2) = round(y);
            
            % draw lines that indicate annotation results and make them
            % visible
            if curr_id == 1 || curr_id == 2
                if record(1,1) >= 0 && record(1,2) >= 0 && record(2,1) >= 0 && record(2,2) >= 0
                    set(head, 'XData', [record(1,1) record(2,1)]);
                    set(head, 'YData', [record(1,2) record(2,2)]);
                    set(head, 'Visible', 'on');
                end
            end
            if curr_id == 3 || curr_id == 4
                if record(3,1) >= 0 && record(3,2) >= 0 && record(4,1) >= 0 && record(4,2) >= 0
                    set(torso, 'XData', [record(3,1) record(4,1)]);
                    set(torso, 'YData', [record(3,2) record(4,2)]);
                    set(torso, 'Visible', 'on');
                end
            end
            if curr_id == 5 || curr_id == 6
                if record(5,1) >= 0 && record(5,2) >= 0 && record(6,1) >= 0 && record(6,2) >= 0
                    set(left_upper_arm, 'XData', [record(5,1) record(6,1)]);
                    set(left_upper_arm, 'YData', [record(5,2) record(6,2)]);
                    set(left_upper_arm, 'Visible', 'on');
                end
            end
            if curr_id == 6 || curr_id == 7
                if record(6,1) >= 0 && record(6,2) >= 0 && record(7,1) >= 0 && record(7,2) >= 0
                    set(left_lower_arm, 'XData', [record(6,1) record(7,1)]);
                    set(left_lower_arm, 'YData', [record(6,2) record(7,2)]);
                    set(left_lower_arm, 'Visible', 'on');
                end
            end
            if curr_id == 8 || curr_id == 9
                if record(8,1) >= 0 && record(8,2) >= 0 && record(9,1) >= 0 && record(9,2) >= 0
                    set(right_upper_arm, 'XData', [record(8,1) record(9,1)]);
                    set(right_upper_arm, 'YData', [record(8,2) record(9,2)]);
                    set(right_upper_arm, 'Visible', 'on');
                end
            end
            if curr_id == 9 || curr_id == 10
                if record(9,1) >= 0 && record(9,2) >= 0 && record(10,1) >= 0 && record(10,2) >= 0
                    set(right_lower_arm, 'XData', [record(9,1) record(10,1)]);
                    set(right_lower_arm, 'YData', [record(9,2) record(10,2)]);
                    set(right_lower_arm, 'Visible', 'on');
                end
            end
            if curr_id == 11 || curr_id == 12
                if record(11,1) >= 0 && record(11,2) >= 0 && record(12,1) >= 0 && record(12,2) >= 0
                    set(left_upper_leg, 'XData', [record(11,1) record(12,1)]);
                    set(left_upper_leg, 'YData', [record(11,2) record(12,2)]);
                    set(left_upper_leg, 'Visible', 'on');
                end
            end
            if curr_id == 12 || curr_id == 13
                if record(12,1) >= 0 && record(12,2) >= 0 && record(13,1) >= 0 && record(13,2) >= 0
                    set(left_lower_leg, 'XData', [record(12,1) record(13,1)]);
                    set(left_lower_leg, 'YData', [record(12,2) record(13,2)]);
                    set(left_lower_leg, 'Visible', 'on');
                end
            end
            if curr_id == 14 || curr_id == 15
                if record(14,1) >= 0 && record(14,2) >= 0 && record(15,1) >= 0 && record(15,2) >= 0
                    set(right_upper_leg, 'XData', [record(14,1) record(15,1)]);
                    set(right_upper_leg, 'YData', [record(14,2) record(15,2)]);
                    set(right_upper_leg, 'Visible', 'on');
                end
            end
            if curr_id == 15 || curr_id == 16
                if record(15,1) >= 0 && record(15,2) >= 0 && record(16,1) >= 0 && record(16,2) >= 0
                    set(right_lower_leg, 'XData', [record(15,1) record(16,1)]);
                    set(right_lower_leg, 'YData', [record(15,2) record(16,2)]);
                    set(right_lower_leg, 'Visible', 'on');
                end
            end
            
            curr_id = curr_id + 1;
            if curr_id > 16
                curr_id = 1;
            end
            
        case 48  % press '0'
            curr_id = 1;  set(h, 'string', '0: Head top');
        case 49
            curr_id = 2;  set(h, 'string', '1: Head bottom');
        case 50
            curr_id = 3;  set(h, 'string', '2: Torso top');
        case 51
            curr_id = 4;  set(h, 'string', '3: Torso bottom');
        case 52
            curr_id = 5;  set(h, 'string', '4: Left arm top');
        case 53
            curr_id = 6;  set(h, 'string', '5: Left elbow');
        case 54
            curr_id = 7;  set(h, 'string', '6: Left arm bottom');
        case 55
            curr_id = 8;  set(h, 'string', '7: Right arm top');
        case 56
            curr_id = 9;  set(h, 'string', '8: Right elbow');
        case 57
            curr_id = 10;  set(h, 'string', '9: Right arm bottom');
        case 113
            curr_id = 11;  set(h, 'string', 'q: Left leg top');
        case 119
            curr_id = 12;  set(h, 'string', 'w: Left knee');
        case 101
            curr_id = 13;  set(h, 'string', 'e: Left leg bottom');
        case 114
            curr_id = 14;  set(h, 'string', 'r: Right leg top');
        case 116
            curr_id = 15;  set(h, 'string', 't: Right knee');
        case 121
            curr_id = 16;  set(h, 'string', 'y: Right leg bottom');
            
        case 28  % left cursor or right cursor, go to previous or next point
            curr_id = curr_id - 1;
            if curr_id < 1  
                curr_id = 16;
            end
        case 29
            curr_id = curr_id + 1;
            if curr_id > 16
                curr_id = 1;
            end
            
        case 32  % space key, go to the next image
            flag = 0;
    end
    
    
    switch curr_id
        case 1  % press '0'
            set(h, 'string', '0: Head top');
        case 2
            set(h, 'string', '1: Head bottom');
        case 3
            set(h, 'string', '2: Torso top');
        case 4
            set(h, 'string', '3: Torso bottom');
        case 5
            set(h, 'string', '4: Left arm top');
        case 6
            set(h, 'string', '5: Left elbow');
        case 7
            set(h, 'string', '6: Left arm bottom');
        case 8
            set(h, 'string', '7: Right arm top');
        case 9
            set(h, 'string', '8: Right elbow');
        case 10
            set(h, 'string', '9: Right arm bottom');
        case 11
            set(h, 'string', 'q: Left leg top');
        case 12
            set(h, 'string', 'w: Left knee');
        case 13
            set(h, 'string', 'e: Left leg bottom');
        case 14
            set(h, 'string', 'r: Right leg top');
        case 15
            set(h, 'string', 't: Right knee');
        case 16
            set(h, 'string', 'y: Right leg bottom');
    end
end

print(hh, '-dbmp', rltfile);
close(hh);