reformat most things

This commit is contained in:
Viktor Barzin 2025-05-07 21:25:40 +00:00
parent bd7c781adb
commit 835494d29f
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
7 changed files with 85 additions and 50 deletions

View file

@ -34,12 +34,16 @@ def calculate_model(image_path):
estimated_sqm = extract_total_sqm(output)
return estimated_sqm, output, predictions_tensor
def improve_img_for_ocr(img: Image):
img2 = np.array(img.convert('L'))
cv2.resize(img2, None, fx=1.2, fy=1.2, interpolation=cv2.INTER_CUBIC)
thresh = cv2.adaptiveThreshold(img2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
thresh = cv2.adaptiveThreshold(
img2, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2
)
return Image.fromarray(thresh)
def calculate_ocr(image_path):
img = Image.open(image_path)
text = pytesseract.image_to_string(img)
@ -51,5 +55,5 @@ def calculate_ocr(image_path):
with open("recalculating.log", "a") as f:
f.write(f"before: {estimated_sqm} after: {estimated_sqm2} - {image_path}\n")
return estimated_sqm2, text2
return estimated_sqm, text