- NOTE: This is our beta version of handwriter
- For the most stable version of handwriter please use:
- install.packages("handwriter")
- to get handwriter from CRAN: https://CRAN.R-project.org/package=handwriter
This readme covers the functionality of the Python-based handwriter
routines.
Here are the step by step instructions for Python Word Separation:
- Ensure that Python is installed. There are several ways: https://www.python.org/downloads/
- Clone the
handwriter
repository to your local machine - Install the following python packages:
pip install opencv-python matplotlib ipython jupyter
- Open up a terminal
- Change your working directory to the
inst/python
directory of thehandwriter
repository. For example, on MacOS, you would runcd /path/to/cloned/handwriter/inst/python
, replacing the path with the actual path on your local machine.
The next set of steps depend on whether you (a) prefer to run the code natively in Python, (b) prefer to run the code from a Jupyter Notebook, or (c) prefer to run the code from R.
- Launch the Python interpreter by calling:
python
- Import the module:
import word_separation as ws
- Split the lines:
input_image="images/w0001_s03_pPHR_r01.png"
# Split the lines
split_images = ws.detect_lines(input_image)
split_images
- Separate the word:
# Display each split image
for split_image in split_images:
ws.show_image(ws.separate_word(file_name=split_image))
- Display the contours!
# Get every word extracted as a contour
all_words = []
for split_image in split_images:
im1_contours = ws.separate_word(file_name=split_image, ret="contours")
all_words.append(ws.annotate_image(split_image, im1_contours))
- Display the Bounding Boxes!
# Let's take a look!
all_words
- Batch Processing
batched = ws.batch_process("images")
- Launch the Jupyter Notebook client by calling:
jupyter notebook
-
Open up
word_separation.ipynb
-
Execute the cells of the notebook
Execute the word_separation.R
script in the inst/python
directory:
# We will need reticulate to call the Python functions
library(reticulate)
# Make sure you're using the right version of Python
use_python("/Users/erichare/.pyenv/shims/python")
# Source in the word separation code from this directory!
source_python("word_separation.py")
# Configure the input image
input_image="images/w0001_s03_pPHR_r01.png"
# Split the lines
split_images = detect_lines(input_image)
split_images
# Display each split image
for (split_image in split_images) {
show_image(separate_word(file_name=split_image))
}
# Get every word extracted as a contour
all_words <- list()
for (split_image in split_images) {
im1_contours = separate_word(file_name=split_image, ret="contours")
all_words[[length(all_words) + 1]] <- annotate_image(split_image, im1_contours)
}
# Let's take a look!
all_words
###
# Batch Processing
###
batch_process("images")