Как исправить TypeError: ожидаемый объект str, bytes или os.PathLike, а не PngImageFile в python - PullRequest
0 голосов
/ 23 апреля 2020

Пожалуйста, найдите ниже код

def get_document_bounds (image, feature): # [START vision_document_text_tutorial_detect_bounds] "" "Возвращает границы документа для изображения." "" Os.environ ['GOOGLE_APPLICATION_CREDENTIALS'] = r ' C: \ DSpython \ bounds. json 'client = vision.ImageAnnotatorClient ()

bounds = []

with io.open(image, 'rb') as image_file:
    content = image_file.read()

image= types.Image(content=content)

response = client.document_text_detection(image=image)
document = response.full_text_annotation

# Collect specified feature bounds by enumerating all document features
for page in document.pages:
    for block in page.blocks:
        for paragraph in block.paragraphs:
            for word in paragraph.words:
                for symbol in word.symbols:
                    if (feature == FeatureType.SYMBOL):
                        bounds.append(symbol.bounding_box)

                if (feature == FeatureType.WORD):
                    bounds.append(word.bounding_box)

            if (feature == FeatureType.PARA):
                bounds.append(paragraph.bounding_box)

        if (feature == FeatureType.BLOCK):
            bounds.append(block.bounding_box)

# The list `bounds` contains the coordinates of the bounding boxes.
# [END vision_document_text_tutorial_detect_bounds]
return bounds

*** Моя цель - извлечь текст из изображения. В рамках этого я создаю границы в этой функции "get document _bounds".

"с io.open (image, 'rb') как image_file:" при открытии изображения с помощью функции io.open. получение вышеуказанного кода.

1 Ответ

0 голосов
/ 23 апреля 2020

Вы хотели поставить

image= types.Image(content=content)

ДО

with io.open(image, 'rb') as image_file:
content = image_file.read()

?

...