使用 GCP 的 Cloud Vision 进行车牌识别
License plate recognition using GCP's Cloud Vision
我们正在开发一个移动应用程序,允许用户上传将存储在 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 来检测和模糊上传到 GCP 存储的图像上的车牌。 Python 代码。这是相关的 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
您必须创建一个自定义模型,上传您的图像训练集(在本例中为车牌)并对其进行训练以生成模型,然后您可以使用该模型发送图像并取回信息。 ..
尝试在同一张图片中使用OBJECT_LOCALIZATION、FACE_DETECTION和TEXT_DETECTION,并在OBJECT_LOCALIZATION中使用"License plate"进行过滤,这样就可以了应有尽有。
我们正在开发一个移动应用程序,允许用户上传将存储在 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 来检测和模糊上传到 GCP 存储的图像上的车牌。 Python 代码。这是相关的 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
您必须创建一个自定义模型,上传您的图像训练集(在本例中为车牌)并对其进行训练以生成模型,然后您可以使用该模型发送图像并取回信息。 ..
尝试在同一张图片中使用OBJECT_LOCALIZATION、FACE_DETECTION和TEXT_DETECTION,并在OBJECT_LOCALIZATION中使用"License plate"进行过滤,这样就可以了应有尽有。