Hi, I'm stupid
This commit is contained in:
14
owocr/ocr.py
14
owocr/ocr.py
@@ -5,6 +5,7 @@ from pathlib import Path
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
|
from math import sqrt
|
||||||
|
|
||||||
import jaconv
|
import jaconv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -192,14 +193,11 @@ class GoogleLens:
|
|||||||
|
|
||||||
def _preprocess(self, img):
|
def _preprocess(self, img):
|
||||||
w,h = img.size
|
w,h = img.size
|
||||||
ratio = w/h
|
if w * h > 3000000:
|
||||||
while True:
|
aspect_ratio = w/h
|
||||||
if h * w < 3000000:
|
new_w = int(sqrt(3000000 * aspect_ratio))
|
||||||
if (w,h) != img.size:
|
new_h = int(new_w / aspect_ratio)
|
||||||
img = img.resize((w, h), Image.LANCZOS)
|
img = img.resize((new_w, new_h), Image.LANCZOS)
|
||||||
break
|
|
||||||
h -= 1
|
|
||||||
w = int(h * ratio)
|
|
||||||
|
|
||||||
image_bytes = io.BytesIO()
|
image_bytes = io.BytesIO()
|
||||||
img.save(image_bytes, format='png')
|
img.save(image_bytes, format='png')
|
||||||
|
|||||||
Reference in New Issue
Block a user