gpt4 book ai didi

python - 使用 GCP 的 Cloud Vision 进行车牌识别

转载 作者:行者123 更新时间:2023-12-03 08:53:41 25 4
gpt4 key购买 nike

我们正在开发一款移动应用,允许用户上传将存储在 GCP 存储桶中的图像。然而,在保存到存储桶之前,我们希望模糊掉可能存在的任何面孔和车牌。我们一直在使用对 GCP 的 Cloud Vision 服务的调用来注释图像中的人脸,效果非常好。然而,车牌注释变得更具挑战性。没有专门检测车牌的选项,但我们似乎仅限于捕获车牌的文本检测,以及图像中的所有其他文本。这不是我们想要的。

关于如何更好地将文本识别范围缩小到仅车牌的任何指示?

以下是我们当前用于检测和收集面部和文本注释数据的 Python 代码示例:

from google.cloud import vision
...
def __annotate(image_storage_url):
result = []

client = vision.ImageAnnotatorClient()

response = client.annotate_image({
'image': {'source': {'image_uri': image_storage_url}},
'features': [
{'type': vision.enums.Feature.Type.FACE_DETECTION}, #works great
{'type': vision.enums.Feature.Type.TEXT_DETECTION}, #too broad
],
})

# record facial annotations
faces = response.face_annotations
for face in faces:
vertices = [(vertex.x, vertex.y)
for vertex in face.bounding_poly.vertices]
result.append(vertices)

# record plate annotations
texts = response.text_annotations
for text in texts:
vertices = [(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices]
result.append(vertices)

return result

谢谢

2020 年 4 月 28 日更新感谢下面 Obed Macallums 的回答(现在标记为答案),我现在有了使用 GCP Cloud Vision 的工作 Python 代码来检测和模糊上传到 GCP 存储的图像上的车牌。下面是相关的Python代码:

from google.cloud import vision
...

def __annotate(image_storage_url, img_dimensions):
result = []

client = vision.ImageAnnotatorClient()

response = client.annotate_image({
'image': {'source': {'image_uri': image_storage_url}},
'features': [
{'type': vision.enums.Feature.Type.FACE_DETECTION},
{'type': vision.enums.Feature.Type.TEXT_DETECTION},
{'type': vision.enums.Feature.Type.OBJECT_LOCALIZATION},
],
})

# Blur faces
faces = response.face_annotations
for face in faces:
vertices = [(vertex.x, vertex.y)
for vertex in face.bounding_poly.vertices]
LOGGER.debug('Face detected: %s', vertices)
result.append(vertices)

# Blur license plates
# Note: localized_object_annotations use normalized_vertices which represent the relative-distance
# (between 0 and 1) and so must be multiplied using the image's height and width
lo_annotations = response.localized_object_annotations
for obj in lo_annotations:
if obj.name == 'License plate':
vertices = [(int(vertex.x * img_dimensions['width']), int(vertex.y * img_dimensions['height']))
for vertex in obj.bounding_poly.normalized_vertices]
LOGGER.debug('License plate detected: %s', vertices)
result.append(vertices)

return result

最佳答案

您必须创建一个自定义模型,上传图像训练集(在本例中为车牌)并训练它生成模型,然后您可以使用该模型发送图像并获取信息...

看看Google Object Detection

关于python - 使用 GCP 的 Cloud Vision 进行车牌识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57277319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com