forked from OlivierBinette/TessTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
84 lines (60 loc) · 2.5 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
output:
github_document:
df_print: kable
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
library(TessTools)
knitr::opts_chunk$set(message=FALSE, warning=FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# TessTools: Tools for the use of Tesseract OCR in R
![Lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)
[![R-CMD-check](https://github.com/OlivierBinette/historical-newspaper-analysis/workflows/R-CMD-check/badge.svg)](https://github.com/OlivierBinette/historical-newspaper-analysis/actions)
Interface to the Tesseract OCR command line tool (version 4) and parsing functions for the analysis of historical newspaper archives. This is under development.
## Installation
Make sure you have the [tesseract](https://github.com/tesseract-ocr/tesseract) command line program installed and available in PATH. You can either [Install Tesseract via pre-built binary package](https://tesseract-ocr.github.io/tessdoc/Home.html)
or [build it from source](https://tesseract-ocr.github.io/tessdoc/Compiling.html).
```bash
$ tesseract
Usage:
tesseract --help | --help-extra | --version
tesseract --list-langs
tesseract imagename outputbase [options...] [configfile...]
```
You can install the development version of `TessTools` from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("OlivierBinette/TessTools")
```
## Example
Download the first issue (1905) of the Duke Chronicle newspaper.
```{r example}
library(TessTools)
issueID = chronicle_meta[1, "local_id"]
zipfile = download_chronicle(issueID, outputdir="data-raw")
```
Run Tesseract OCR on the newspaper scans and extract text paragraphs together with their bounding boxes.
```{r, cache=TRUE}
hocrfiles = hocr_from_zip(zipfile, outputdir="data-raw/hocr", exdir="data-raw/img")
# Extract paragraph text
text = paragraphs(hocrfiles)
text[[1]][9:11, ] # Some paragraphs on the first page
```
Visualize the result using [hocrjs](https://github.com/kba/hocrjs):
```{r}
webpages = visualize_html(hocrfiles, outputdir="data-raw/html") # webpage is at data-raw/html/dchnp71001-html
browseURL(webpages[[1]]) # Note: bring up the hocrjs menu and select "show background image"
```
![](hocrjs.png)
## Ground truth
Paragraphs of the first issue have been annotated according to the article to which they belong.
```{r, max.print=3}
# Ground truth for first page
vol1_paragraphs_truth[[1]][9:11, ]
```