首页 > 解决方案 > 从图像中检测 URL

问题描述

我有一些包含多种 URL 的图像,我正在尝试将其转换为文本并提取边界框。我尝试使用 google vision,它在短 URL 上表现良好,但它通常会忽略整个长 URL。我想这是因为长 URL 被认为是非英文字符串。有什么办法可以改善这个问题吗?

这是一个例子:

在此处输入图像描述

基本上,代码只是将图像发送到 Google vision。然后将边界框(顶点)绘制到图像。

from google.cloud import vision
import io

path = "test3.jpg"
client = vision.ImageAnnotatorClient()

with io.open(path, "rb") as image_file:
    content = image_file.read()

image = vision.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations

# Draw boundary box
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure

figure(figsize=(12, 12), dpi=80)

im = Image.open(path)

for text in texts:
    vects = text.bounding_poly.vertices
    draw = ImageDraw.Draw(im)
    draw.polygon(
        [vects[0].x, vects[0].y, vects[1].x, vects[1].y, vects[2].x, vects[2].y, vects[3].x, vects[3].y], None, "red"
    )

plt.imshow(im)
plt.savefig("output.png")
plt.show()

标签: pythoncomputer-visiongoogle-vision

解决方案


推荐阅读