我正在尝试编写手写识别软件,并需要用户输入。我可以成功使用imfreehand(带参数,闭= 0)函数让用户在空白绘图轴上面书写。但是,我有两个问题:
我需要做2,因为,我会将手写与存储在库中的训练图像进行比较。
关于如何克服这些或任何替代方案的任何想法?
感谢。
答案 0 :(得分:2)
要先回答第二个问题,您可以使用getframe
。这是一个最小的例子:
% --- Free hand drawing
imfreehand('closed', 0);
% --- Get the image
axis off
F = getframe;
Img = F.cdata;
% --- Display the image
figure
imshow(Img);
然后,为了回答关于线条粗细的第一个问题,它有点棘手。您必须获得曲线的坐标plot
,并使用所需的厚度,然后使用getframe
。
由于背景颜色和轴刻度,使应用程序的所有内容都干净有点复杂,但这是一个尝试:
clf
xl = get(gca, 'Xlim');
yl = get(gca, 'Ylim');
h = imfreehand('closed', 0);
% --- Get the curve coordinates
C = get(h, 'Children');
pos = C(5).Vertices;
% --- Re-plot the curve with a thick line
clf
plot(pos(:,1), pos(:,2), 'k', 'Linewidth', 5);
xlim(xl);
ylim(yl);
% --- Get the image
F = getframe;
Img = rgb2gray(F.cdata);
Img(Img>0) = 255;
% --- Display the image
clf
imshow(Img);
希望这有帮助!