GitHub30/winocr

object has no attribute 'XXXX'

ERETIERE opened this issue · 1 comments

Here is my code, and I don't know how to find which attributes my object winsdk_Windows_Foundation.IAsyncOperation has.

import winocr
from PIL import Image
import cv2
import pprint

img = cv2.imread('dufgs.png')
result = winocr.recognize_cv2(img)
pprint.pprint({
# 'text_angle': result.text_angle,
'text': result.text,
'lines': [{
'text': line.text,
'words': [{
'bounding_rect': {'x': word.bounding_rect.x, 'y': word.bounding_rect.y, 'width': word.bounding_rect.width, 'height': word.bounding_rect.height},
'text': word.text
} for word in line.words]
} for line in result.lines]
})

Result :
Traceback (most recent call last):
File "c:\Users\evan1\Desktop\test.py", line 11, in
'text': result.text,
AttributeError: '_winsdk_Windows_Foundation.IAsyncOperation' object has no attribute 'text'

Same thing with other attribute like 'text_angle' etc.

Hi, I found what my error was.
I was unable to get a result.text because the return of my OCR wasn't an OcrResult object.
It wasn't an OcrResult because I wasn't waiting for the recognize_async function to do its job.

:)