python - 从图像中检测 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()
解决方案
推荐阅读
- odoo - Aeroo 报告行编号
- python - 美丽的汤没有获取所有的 html
- networking - {active, false}, {active, true} 和 {active, once} 有什么区别?
- python - 将 None 作为 pygame 中的位置处理
- firebase - 谷歌身份验证中的用户名颤动
- javascript - 在 javascript 中使用 filter() 方法查找数组中的最大数
- python - 如何解释聚类结果?
- cmake - CPack 禁用 add_subdirectory() 下不同项目的组件
- c - 你如何在 C 中编写 hexdump -C 函数?
- c++ - noexcept 不被衰减移除