gpt4 book ai didi

python - 类型错误 : Scalar value for argument 'color' is not numeric in openCV

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:10 36 4
gpt4 key购买 nike

这是我的代码

im = cv2.imread('luffy.jpg')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,127,255,0)

contours,h = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours:
moment = cv2.moments(cnt)
c_y = moment['m10']/(moment['m00']+0.01)
c_x = moment['m01']/(moment['m00']+0.01)
centroid_color = im[c_x,c_y]
centroid_color = np.array((centroid_color[0],centroid_color[1],centroid_color[2]))
print type(centroid_color)
cv2.fillPoly(im,cnt,centroid_color)

我在最后一行尝试将 centroid_color 传递给颜色参数时遇到该错误。是<type 'numpy.ndarray'>并且我已经能够将此数据类型作为其他实例中的颜色成功传递到 cv2.fillPoly 中,所以我不确定为什么它会在这里出现问题。

最佳答案

centroid_color = tuple ([int(x) for x in centroid_color])

关于python - 类型错误 : Scalar value for argument 'color' is not numeric in openCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34956828/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com