Text to Handwriting Robot With Python
by tapish101 in Circuits > Robots
1456 Views, 3 Favorites, 0 Comments
Text to Handwriting Robot With Python
I am currently persuing bachelor degree and from the grace of Covid everything is online and the number of assignment in online mode is out of the roof. Its look like I am writing for half of my life. Now I understand that pain of others much better, writing and writing without understanding not wanting to write. So I tried to write the script for my handwriting copier in python. And since I want to make my fake handwriting more realistic so I took full liberty on making everything random. As someone well said "Imperfection is the virtual perfection".
You can get my code here from GitHub and the follow the instructions in readme.md to make it work, all you need is python and it’s pillow library. But It will be in my handwriting.
For making its more personal follow the instructions below.
UPDATE:
Updated to rotate and scale each char for more randomness. Thanks to FabriceA6 for the idea.
Supplies
A computer with python installed in it (check here if need help)
Python pillow library (for help here)
Any text editor
A device with camera
Photo Editor
Photo crop and background remover (convert the image to .png format)
Collecting Handwriting Data
>Take a blank ruled page
>Write all the characters and numbers on that page
>Take the photo of that page and align the page straight
>Crop the individual character and remove the background and convert the image to .png format
>Save all the images to one folder (in my case I named the folders Data0 to Data4 as i have repeated this step four time for more randomness)
Editing the Source Folder
Put the images with correct images names from older images and keep the path to the folder same. Like the tapish folder have my all data folder similarly you can create your own folder there with your name and data folders, don't forget to change the 'id' variable name to your own folder name on the top of handwriting.py.
There are some variables at the start oh the code that needs to be change for better results.
And the Source folder also have the page image that you can change but keep the image name same.
Yeah.. you are pretty much done here, write something in input.txt file and run the script. I am executing from terminal here.
Code Explaination
The code is actually pretty simple. First it loads the input.txt file and then pass the whole text to textTOimg(), that iterate one by one and give the name to each character which are later used to paste the image of that character over the page image. Every think else in the code manages the exact placement of the text and the page number.
The character '^' and the combination '^~' are reserved. '^' used to write on the left of the page margin and "^~" starts the new page from there.
The output images will be in the output folder.
My Thoughts
For me this little python program is just enough not to get caught but I want to improve it much more than this like adding image b/w text and the ruled page line are just too perfectly straight and writing on the header of the page, like your name and info all that stuff.Choosing b/w the diff page images would also be helpful.
Also the step for collecting the data is very repetitive and boring, when you have to do it five times its like doing it for infinite. Here is a cheap trick, i did it thrice and copy the paste the data in remaining two folders, may be this will help you:). Initially i thought having five folders to chose from will give more randomness to the text.
Tilt(Updated)
Updated outputs are attached above, as you can notice this quick & dirty way cause the chars to loose their smoothness (more noticeable when zoomed).
So, there is 'tilt' variable at the top of the code that you can "False" to go to the last ver of code, Its now upto your own personal preference.