首页 > 解决方案 > 如何使用 Google Cloud Vision API 计算图像中的汽车数量?

问题描述

我需要使用Python 中的 Google Cloud Vision API 计算图像中包含的所有汽车。我现在只取图像的标签。

import io
import os
from google.cloud import vision
from google.cloud.vision import types
client = vision.ImageAnnotatorClient();
file_name = os.path.join(
    os.path.dirname(__file__),
    'car.jpg');
with io.open(file_name,'rb') as image_file:
    content = image_file.read();
image = types.Image(content=content)
response = client.label_detection(image=image)
print(response)

标签: pythongoogle-cloud-vision

解决方案


Label detection will detects a set of categories that are proper to the picture as explained here. I don't think it could be used to count cars since it will return some related labels (e.g car, motor vehicle, city car...) for all the cars but without specifying the number of cars. So same label could be returned for 3, 5 or other number of cars.


推荐阅读