【发布时间】: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);
现在的问题是,插入的文字是黑色的,看不清楚。
【问题讨论】:
-
什么是阶跃函数?因为 AFAIK 是这个:uk.mathworks.com/help/control/ref/step.html 并且它绝对不被用作/用于您想要做的事情。
-
抱歉,我最终找到了 videoPlayer 的
step。但是(非常短的)文档似乎表明只接受 2 个输入。uk.mathworks.com/help/vision/ref/vision.videoplayer.step.html
标签: matlab computer-vision matlab-cvst