www.gusucode.com > vision 源码程序 matlab案例代码 > vision/InsertNumbersAndStringsOnAnImageExample.m

    %% Insert Numbers and Text on Image
%
%%
% Read the image.
I = imread('board.tif');
%%
% Create texts that contain fractions.
text_str = cell(3,1);
conf_val = [85.212 98.76 78.342]; 
for ii=1:3
   text_str{ii} = ['Confidence: ' num2str(conf_val(ii),'%0.2f') '%'];
end
%%
% Define the positions and colors of the text boxes.
position = [23 373;35 185;77 107]; 
box_color = {'red','green','yellow'};
%%
% Insert the text with new font size, box color, opacity, and text color.
RGB = insertText(I,position,text_str,'FontSize',18,'BoxColor',...
    box_color,'BoxOpacity',0.4,'TextColor','white');
%%
% Display the image.
figure
imshow(RGB)
title('Board');