在Matlab中心(http://www.mathworks.com/matlabcentral/answers/26033-how-to-insert-text-into-image)中,我找到了以下代码:
Text = sprintf('Create text inserter object \nwith same property values');
H = vision.TextInserter(Text);
H.Color = [1.0 1.0 0];
H.FontSize = 20;
H.Location = [25 25];
I = im2double((imread('football.jpg')));
InsertedImage = step(H, I);
imshow(InsertedImage);
不使用计算机视觉系统工具箱怎么办?
谢谢
跟进我的评论:
A = imread('football.jpg');
YourText = sprintf('Create text inserter object \nwith same property values');
figure;
imshow(A);
hText = text(25,25,YourText,'Color',[1 1 0],'FontSize',20);
提供以下内容:
查看文档页面,查看所有可用于修改/自定义文本的选项。注意,您不必使用sprintf
生成字符串,但是\n
必须在内部使用换行符()sprintf
才能起作用。
编辑为了回应您在下面的评论,如果您需要保存嵌入了文本的图像,则可以使用getframe获取图形的内容,然后进行隐式保存:
hFrame = getframe(gca) %// Get content of figure
imwrite(hFrame.cdata,'MyImage.tif','tif') %// Save the actual data, contained in the cdata property of hFrame
编辑#2作为使用的替代方法getframe
,这里提出了2个不错的主意,即使用saveas或avi文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句