【问题标题】:MATLAB vision.TextInserter does not insert textMATLAB vision.TextInserter 不插入文本
【发布时间】:2015-05-15 11:06:37
【问题描述】:

我正在尝试将文本消息插入图像。它不显示,我没有收到任何错误。

close all
clear all
clc

hVideoPlayer = vision.VideoPlayer;
hVideoFileReader = vision.VideoFileReader;
hVideoFileReader.Filename = 'img1.jpg';

frame = step(hVideoFileReader);


hcsc = vision.ColorSpaceConverter;
hcsc.Conversion = 'RGB to intensity';
frame = step(hcsc, frame);

at = vision.Autothresholder;
frame = step(at, frame);


ccl = vision.ConnectedComponentLabeler;
[L NUM] = step(ccl, frame);

holeObjCount = 0;

for i=1:NUM
    framei = changem(L==i, 1, i);

    framei = imcomplement(framei);

    [Li NUMi] = step(ccl, framei);

    if NUMi > 1
        holeObjCount = holeObjCount + 1;
    end

end

message = sprintf('%d of %d objects have holes.', holeObjCount, NUM);
disp(message);

osdMsg = vision.TextInserter('%d of %d objects have holes.',... 
                             'Color', uint8([255, 255, 255]), ...
                             'Location', [10 10],...
                             'FontSize', 22);
%The problem is here
frame = step(osdMsg, frame, int32([holeObjCount NUM]));

step(hVideoPlayer, frame); 

release(hVideoFileReader);

release(hVideoPlayer);

问题是由于图像的色彩空间。我试图在无法自然显示的黑白图像上显示 RGB 彩色文本。

去掉颜色属性后,我可以看到文字了

osdMsg = vision.TextInserter('%d of %d objects have holes.',... 
                             'Location', [10 10],...
                             'FontSize', 22);

现在的问题是,插入的文字是黑色的,看不清楚。

【问题讨论】:

标签: matlab computer-vision matlab-cvst


【解决方案1】:

问题在于,阈值化后frame 是一个逻辑数组。要显示文本,请使用im2uint8 将其转换为uint8

其他一些提示:由于您使用的是单个图像而不是视频,因此您可以使用imread 而不是vision.VideoFileReader 来读取它。您也可以使用imshow 而不是vision.VideoPlayer 来读取它同样的原因。此外,如果您有 MATLAB R2013a 或更高版本,您可以使用 insertText 函数而不是 vision.TextInserter

【讨论】:

  • im2uint8() 是我需要的。但即使我将文本的颜色设置为红色 'Color', uint8([255, 0, 0]),... 它仍然显示白色文本。
  • 为此,您需要将图像设置为 RGB:frame = cat(3, frame, frame, frame)。更好的是,如果可以,请使用insertText(),因为它会为您做到这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多