OpenCV Scalar value for argument ‘color‘ is not numeric错误处理

import cv2

cur_color = np.array([128,0,128]).astype(np.uint8)
cv2.polylines(cvImage, [ndata], isClosed=True, color=cur_color, thickness=thickness)

以上代码在OpenCV中函数的color参数会触发错误:

OpenCV Scalar value for argument ‘color‘ is not numeric

这里看color参数传递的数值是uint8,错误提示有些令人不解。实际上这里出错的主要原因是传递的是np.array导致的,如果是tuple或list则正常。可以将np.array类型转换为tuple,cur_color = tuple([int(x) for x in cur_color]),更新后如下:

import cv2

cur_color = np.array([128,0,128]).astype(np.uint8)
cur_color = tuple([int(x) for x in cur_color])
cv2.polylines(cvImage, [ndata], isClosed=True, color=cur_color, thickness=thickness)

你可能感兴趣的:(Python,CV,opencv,计算机视觉,python)