Python 我试图找到感兴趣的区域并在函数中使用cv2.Polyline,但它给出了错误?
我的功能Python 我试图找到感兴趣的区域并在函数中使用cv2.Polyline,但它给出了错误?,python,opencv,Python,Opencv,我的功能 import numpy as np def region_of_interest(image): height = image.shape[0] #pixel value to be filled in mask #as value on depends on the number of channel if len(img.shape) > 2: mask_color_ignore = (25
import numpy as np
def region_of_interest(image):
height = image.shape[0]
#pixel value to be filled in mask
#as value on depends on the number of channel
if len(img.shape) > 2:
mask_color_ignore = (255,) * img.shape[2]
else:
mask_color_ignore = 255
#shape of our interest
triangle = np.array([[(0, (5/6)*height), (900, (5/6)*height), (400, (1/6)*height)]])
mask = np.zeros_like(image)
try:
cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )
except Exception as e:
print(e)
return mask
出现错误
cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )
^
SyntaxError: positional argument follows keyword argument
请帮助我理解错误的原因以及它为什么会出现在这里
我对Python中的openCv非常陌生(不仅仅是openCv),关键字参数(用name=value
指定的参数)必须位于位置参数(仅通过值传递的参数)之后
因此
cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )
当您在color=mask\u color\u ignore
之后传递1
时,您会得到错误
最佳做法是将
1
作为命名参数传递。与错误消息所述完全相同。在python中,非关键字参数必须位于关键字参数之前。你有。。。颜色=遮罩颜色忽略,**1**,线型…
。1需要附加关键字,或在关键字参数之前移动。