Skip to content

Instantly share code, notes, and snippets.

@lawlesst
Last active June 3, 2021 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlesst/1c110348f9ad59dcdd7a0a26d722854d to your computer and use it in GitHub Desktop.
Save lawlesst/1c110348f9ad59dcdd7a0a26d722854d to your computer and use it in GitHub Desktop.
Constellate Binder Tesseract
Display the source blob
Display the rendered blob
Raw
{
cells: [
{
cell_type: "code",
execution_count: null,
metadata: { },
outputs: [ ],
source: [
"!conda install -c conda-forge -y tesseract"
]
},
{
cell_type: "code",
execution_count: 2,
metadata: { },
outputs: [
{
name: "stdout",
output_type: "stream",
text: [
"Requirement already satisfied: Pillow in /srv/conda/envs/notebook/lib/python3.7/site-packages (8.2.0) ",
"Requirement already satisfied: pytesseract in /srv/conda/envs/notebook/lib/python3.7/site-packages (0.3.7) "
]
}
],
source: [
"!pip install Pillow pytesseract"
]
},
{
cell_type: "code",
execution_count: 3,
metadata: { },
outputs: [
{
name: "stdout",
output_type: "stream",
text: [
"/srv/conda/envs/notebook/bin/tesseract "
]
}
],
source: [
"!which tesseract"
]
},
{
cell_type: "code",
execution_count: 4,
metadata: { },
outputs: [
{
name: "stdout",
output_type: "stream",
text: [
"--2021-06-02 14:10:53-- https://static.poetryfoundation.org/jstor/i20580328/pages/16.png ",
"Resolving static.poetryfoundation.org (static.poetryfoundation.org)... 104.22.3.86, 104.22.2.86, 172.67.7.91, ... ",
"Connecting to static.poetryfoundation.org (static.poetryfoundation.org)|104.22.3.86|:443... connected. ",
"HTTP request sent, awaiting response... 200 OK ",
"Length: 70206 (69K) [image/png] ",
"Saving to: ‘test.png’ ",
" ",
"test.png 100%[===================>] 68.56K --.-KB/s in 0.001s ",
" ",
"2021-06-02 14:10:53 (64.9 MB/s) - ‘test.png’ saved [70206/70206] ",
" "
]
}
],
source: [
"!wget -O test.png https://static.poetryfoundation.org/jstor/i20580328/pages/16.png "
]
},
{
cell_type: "code",
execution_count: 5,
metadata: { },
outputs: [
{
name: "stdout",
output_type: "stream",
text: [
"Robert Frost ",
" ",
"TEN MILLS ",
" ",
"PRECAUTION ",
" ",
"I never dared be radical when young ",
"For fear it would make me conservative when old. ",
" ",
"THE SPAN OF LIFE ",
" ",
"The old dog barks backward without getting up. ",
"I can remember when he was a pup. ",
" ",
"PERTINAX ",
" ",
"Let chaos storm! ",
"Let cloud shapes swarm! ",
"I wait for form. ",
" ",
"ASSERTIVE ",
" ",
"Let me be the one ",
"To do what is done. ",
" ",
"TENDENCIES CANCEL ",
" ",
"Will the blight kill the chestnut? ",
"The farmers rather guess not. ",
"It keeps smouldering at the roots ",
"And sending up new shoots, ",
" ",
"Till another parasite ",
" ",
"Shall come to kill the blight. ",
" ",
"{3] ",
" ",
" "
]
}
],
source: [
"try: ",
" from PIL import Image ",
"except ImportError: ",
" import Image ",
"import pytesseract ",
" ",
"# If you don't have tesseract executable in your PATH, include the following: ",
"pytesseract.pytesseract.tesseract_cmd = r'/srv/conda/envs/notebook/bin/tesseract' ",
"# Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract' ",
" ",
"# Simple image to string ",
"print(pytesseract.image_to_string(Image.open('test.png')))"
]
},
{
cell_type: "code",
execution_count: null,
metadata: { },
outputs: [ ],
source: [ ]
}
],
metadata: {
kernelspec: {
display_name: "Python 3",
language: "python",
name: "python3"
},
language_info: {
codemirror_mode: {
name: "ipython",
version: 3
},
file_extension: ".py",
mimetype: "text/x-python",
name: "python",
nbconvert_exporter: "python",
pygments_lexer: "ipython3",
version: "3.7.3"
},
toc: {
base_numbering: 1,
nav_menu: { },
number_sections: true,
sideBar: true,
skip_h1_title: false,
title_cell: "Table of Contents",
title_sidebar: "Contents",
toc_cell: false,
toc_position: { },
toc_section_display: true,
toc_window_display: false
}
},
nbformat: 4,
nbformat_minor: 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment