(edited because it was sugested to clarify and format my question)
i have a proyect where i upload an image using a FileLoader, my code in Deepnote is using opencv-python and easyocr should read the text on an image and present it on a textbox text_area_2_change, also it shows it on anvil the image uploaded. the issue im having is that im not sure if im calling incorrectly the functions, im not using the correct variables or both, the code is fairly simple, but i just started using anvil, and my time for this proyect is short, can someone look at it an might point me in the right direcction?
-this is what i have in my Anvil form:
def file_loader_1_change(self, file, **event_args):
"This method is called when a new file is loaded into this FileLoader"
result = anvil.server.call('analisis', file)
self.image_1.source = file
self.text_area_2_change.text = f"{resultado}"
-for the moment only the image is shown
-the variable image will read an image using cv2.read(“whatevernameimageiwantittoread”), reader tells to use easyocr to recognice the characters on the image, use the spanish lenguage and to use the cpu, not the gpu, and result will use reader.readtext to analize the image stored in image,
the second part draws rectangles around the words, and put on top of it the interpretation, the interpretation or text readed and presented is the one i want on the textbox
-this is in my Deepnote notebook:
import easyocr
import cv2
import imutils
import numpy as np
from PIL import Image
!apt update
!apt install ffmpeg libsm6 libxext6 -y
reader = easyocr.Reader(["es"], gpu=False)
image = cv2.imread("9.jpg")
result = reader.readtext(image, paragraph=False)
def resumeimagen(result):
for res in result:
print("res:", res)
pt0 = res[0][0]
pt1 = res[0][1]
pt2 = res[0][2]
pt3 = res[0][3]
cv2.rectangle(image, pt0,(pt1[0], pt1[1] -23), (166, 56, 242), -1)
cv2.putText(image, res[1],(pt0[0], pt0[1] -3), 2, 0.8, (255, 255, 255), 1)
cv2.rectangle(image, pt0, pt2, (166, 56, 242), 2)
cv2.circle(image, pt0, 2, (255, 0, 0), 2)
cv2.circle(image, pt1, 2, (0, 255, 0), 2)
cv2.circle(image, pt2, 2, (0, 0, 255), 2)
cv2.circle(image, pt3, 2, (0, 255, 255), 2)
return res
import anvil.media
@anvil.server.callable
def analisis(file):
with anvil.media.TempFile(file) as img:
reader = easyocr.Reader(["es"], gpu=False)
image = cv2.imread(img)
result = reader.readtext(image, paragraph=False)
resultado = resumeimagen()
return result, resultado