Reputation: 502
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:
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.
Upvotes: 1
Views: 797
Reputation: 5188
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 !
Upvotes: 2