所以我有一些代码,给出了三个语法错误,但它运行良好,几乎就像语法错误是化妆品或其他东西。在一个使用Google cloud vision API的大型项目中,我可能会提供更多诊断问题所需的代码,但我认为它非常容易解析,我认为可能很容易看到整个方法,从而知道什么是重要的
(出错的代码基本上是从google vision API示例中提取的,但我确实需要对其进行一些调整,所以可能这就是问题所在,但它是有效的,所以我感到困惑)
(同样值得注意的是,问题可能出在visual studio代码上,而不是代码本身)
def检测对象线(路径):
“”“本地化本地图像中的对象。”。
def detect_object_cord(path):
"""Localize objects in the local image.
Args:
path: The path to the local file.
"""
client = vision.ImageAnnotatorClient(credentials=GOOGLE_APPLICATION_CREDENTIALS)
f = 1
with open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)#content=content
objects = client.object_localization(image=image).localized_object_annotations
print('Number of objects found: {}'.format(len(objects)))
for object_ in objects:
print('\n{} (confidence: {})'.format(object_.name, object_.score))
for vertex in object_.bounding_poly.normalized_vertices:
if FaceCount == 1:
if f<= 4:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 2:
if f<= 8 and f> 4:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 3:
if f<= 12 and f > 8:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 4:
if f<= 16 and f > 12:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 5:
if f<= 20 and f > 16:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 6:
if f<= 24 and f > 20:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 7:
if f<= 28 and f > 24:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 8:
if f<= 32 and f > 28:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 9:
if f<= 36 and f > 32:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
if FaceCount == 10:
if f<= 40 and f > 36:
cordAryX.append(vertex.x )
cordAryY.append(vertex.y )
f = f+1
print()
print('user selection was: ' + FaceChoice)
print('x: ', end='')
print(cordAryX)
print('y: ', end='')
print(cordAryY)
这三行的错误都是“SyntaxError:invalid syntax”,错误行是:
“打开(路径'rb')作为图像_文件:”
“content=image_file.read()”
“对于对象中的对象:”
或者至少这些是问题小组讨论的内容
我努力地看着它,但我的大脑看不到任何错误。我看不到任何不合适的缩进或空格。总的来说,我看不出有什么问题。我试过删除这些行,然后用手重新打字,但没有用。正如我之前所说的,代码按预期运行和工作,但错误让我抓狂,我只想让它看起来完美。