如何解决为什么在使用Google Vision时出现列表索引超出范围错误?
我使用的是直接来自Google Api的代码。
import argparse
import io
import os
from numpy import random
import pandas as pd
from pillow_utility import draw_borders,Image
from google.cloud import vision
from google.cloud.vision import types
from PIL import Image,ImageDraw
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="<path to json token>"
def get_crop_hint(path):
#Detect crop hints on a single image and return the first result.
client = vision.ImageAnnotatorClient()
with io.open(path,'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
crop_hints_params = vision.types.CropHintsParams(aspect_ratios=[1])
image_context = vision.types.ImageContext(crop_hints_params=crop_hints_params)
response = client.crop_hints(image=image,image_context=image_context)
hints = response.crop_hints_annotation.crop_hints
# Get bounds for the first crop hint using an aspect ratio of 1:1
vertices = hints[0].bounding_poly.vertices
return vertices
针对Tif图像运行此命令时,出现以下错误:
File "googlecrop.py",line 31,in get_crop_hint
vertices = hints[0].bounding_poly.vertices
IndexError: list index (0) out of range
但是,如果我对保存为Jpeg的同一张图片运行它,则它将按预期工作。这不是我最初想到的文件大小错误,因为那是完全不同的错误消息。
我的最终目标是能够检测裁剪提示,并使用我选择的边界框裁剪到该框。有人知道这是否可能吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。