-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement reading from pdf on s3 bucket
- Loading branch information
1 parent
b88fb36
commit 6690336
Showing
6 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# ocr-textbook | ||
Optical Character Recognition using Python | ||
|
||
# Technologies | ||
|
||
- Python | ||
- Amazon S3 - AWS | ||
- Git | ||
- ТeceractOCR | ||
- Pillow | ||
- PyMuPDF | ||
|
||
# Installation | ||
|
||
Python 3.7+ is required. | ||
|
||
``` | ||
git clone https://github.com/anna-lybid/planetarium-api-project.git | ||
cd planetarium-api-project | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
python manage.py migrate | ||
python manage.py runserver | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import cv2 as cv | ||
from PIL import Image | ||
import pytesseract | ||
|
||
image_file = "Images/s3-bucket-with-cv.jpg" | ||
|
||
image = cv.imread(image_file) | ||
|
||
if image is not None: | ||
cv.imshow("Image", image) | ||
cv.waitKey(0) | ||
cv.destroyAllWindows() | ||
else: | ||
print("Image is not found or could not be opened.") | ||
|
||
img = Image.open(image_file) | ||
|
||
text = pytesseract.image_to_string(img) | ||
|
||
print(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import boto3 | ||
import fitz | ||
import pytesseract | ||
from PIL import Image | ||
|
||
bucket_name = "anna-lybid-s3-demo" | ||
key = "My CV/CV. Anna Lybid. Python developer.pdf" | ||
|
||
s3 = boto3.client("s3") | ||
|
||
response = s3.get_object(Bucket=bucket_name, Key=key) | ||
|
||
pdf_data = response["Body"].read() | ||
|
||
pdf_document = fitz.open(stream=pdf_data, filetype='pdf') | ||
|
||
first_page = pdf_document.load_page(0) | ||
image = first_page.get_pixmap() | ||
|
||
image_path = "images/converted_from_pdf.png" | ||
image.save(image_path) | ||
|
||
img = Image.open(image_path) | ||
text = pytesseract.image_to_string(img) | ||
|
||
print(text) |
Binary file not shown.