Created
May 1, 2024 16:15
-
-
Save blopa/ea2e3ffdb43ac9b1b86141752ac5266f to your computer and use it in GitHub Desktop.
Code for post "Transforming manga pages for lazy western readers"
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
import easyocr | |
def extract_text_from_manga(base_image): | |
reader = easyocr.Reader(['en']) | |
if isinstance(base_image, Image.Image): | |
base_image = np.array(base_image) | |
results = reader.readtext(base_image, detail=1) | |
extracted_data = [] | |
for result in results: | |
data = { | |
"text": result[1], | |
"location": [int(point) for point in result[0][0]], | |
"width": int(result[0][2][0] - result[0][0][0]), | |
"height": int(result[0][2][1] - result[0][0][1]) | |
} | |
extracted_data.append(data) | |
return json.dumps(extracted_data, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment