简体   繁体   中英

How to get user freehand input in matlab?

I am trying to write a handwriting recognization software, and need user input. I can successfully use imfreehand (with parameter, closed = 0) function to let the user write on top of a blank plot axis. However, I have two issues with that:

  1. I cannot control the thickness of the lines
  2. I cannot convert the scribble into image

I need to do 2, because, I will be comparing the handwriting with training images stored in the library.

Any idea on how to get over these or any alternatives?

Thanks.

To answer your second question first, you can use getframe . Here is a minimal exemple:

% --- Free hand drawing
imfreehand('closed', 0);

% --- Get the image
axis off
F = getframe;
Img = F.cdata;

% --- Display the image
figure
imshow(Img);

Then, to answer your first question regarding line thickness, it's a little bit more tricky. You have to get the coordinates of the curve, plot it with the desired thickness and then use getframe .

It's a little more complicated to make everything clean with respect to your application because of the background color and the axes scales, but here is a try:

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

Hope this helps !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM