Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save blopa/ea2e3ffdb43ac9b1b86141752ac5266f to your computer and use it in GitHub Desktop.
Save blopa/ea2e3ffdb43ac9b1b86141752ac5266f to your computer and use it in GitHub Desktop.
Code for post "Transforming manga pages for lazy western readers"
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