如何在matlab中获得用户的徒手输入?

时间:2015-03-28 16:51:06

标签: matlab image-processing ocr roi handwriting-recognition

我正在尝试编写手写识别软件,并需要用户输入。我可以成功使用imfreehand(带参数,闭= 0)函数让用户在空白绘图轴上面书写。但是,我有两个问题:

  1. 我无法控制线条的粗细
  2. 我无法将涂鸦转换为图像
  3. 我需要做2,因为,我会将手写与存储在库中的训练图像进行比较。

    关于如何克服这些或任何替代方案的任何想法?

    感谢。

1 个答案:

答案 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);

希望这有帮助!