目前我正在试用谷歌视觉。我收集了大量的图片,现在我想用谷歌视觉标记这些图片。
到目前为止,我有一个.csv文件,其中第一列包含图像的路径。现在,我尝试在路径上循环,然后将相应的标签添加到第二列。
import os
import io
from google.cloud import vision
import csv
import pandas as pd
from google.cloud.vision import types
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'C:UsersuserPycharmProjectsTest1ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()
csvPath = r'C:UsersuserPycharmProjectsTest1picturesTests.csv'
with io.open(csvPath, 'rb') as csv_file:
for lines in csv_file:
with io.open(lines, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations.description
因此,在运行完这段代码后,我希望有一个.csv文件,其中包含第二列中的标签,此时我也会收到这个错误
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/Test1/googleVisionTests.py", line 17, in <module>
with io.open(lines, 'r') as image_file:
OSError: [Errno 22] Invalid argument: b'C:/Users/user/PycharmProjects/Test1/pictures/35mm-tR-hmR1ZGmE-unsplash.jpgrn'
我希望有人能帮忙!
谢谢!
替换
with io.open(csvPath, 'rb') as csv_file:
带有
with io.open(csvPath, 'r') as csv_file:
"rb"以二进制模式打开文件,csv文件不需要此模式