python - 如何使用 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)
解决方案
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.
推荐阅读
- python - 如何为 TensorFlow 预处理 pandas 数据集
- python - 如何在python中解析字符串中的字符串替换字段?
- eucalyptus - Euca 5.0 无节点控制器
- python - 如何更改数据框中与包含浮点值和字符串值混合的标准匹配的行的文本字体粗细?
- javascript - Vuetify v-select 不支持键盘 tab 键
- flutter - 如何使用 3 个容器创建动画
- jquery - 使用预签名 URL 将文件上传到 AWS S3
- flutter - TabBar 文本未在 setState 上的 NestedScrollView 内更新
- python-sphinx - 如何控制 readthedocs/sphinx 页面链接的图像预览?
- powershell - PowerShell:操作现有变量字段值