【发布时间】:2019-07-30 17:46:26
【问题描述】:
我们正在开发一款移动应用,允许用户上传将存储在 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 的回答(现在标记为答案),我现在可以使用 Python 代码使用 GCP Cloud Vision 来检测和模糊上传到 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
【问题讨论】:
标签: python image-processing google-cloud-platform google-cloud-vision