I am trying to pass a ndarray into this line: cv2.fillPoly(im, pts=[cnt],color=(centroid_color[0],centroid_color[1],centroid_color[2]))
centroid_color looks like this: [ 0 255 0]
and is of type <type 'numpy.ndarray'>
However, I keep getting this error: TypeError: Scalar value for argument 'color' is not numeric.
How would I convert this properly?
edit: my current updated code that still gets the same error:
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]))
r = lambda: random.randint(0,255)
print type(centroid_color)
cv2.fillPoly(im,cnt,centroid_color)
For me the only thing that worked:
self.points = np.int32(np.vstack([
np.random.uniform(0, bounds[1], 3),
np.random.uniform(0, bounds[0], 3)
]).T)
color = np.uint8(np.random.uniform(0, 255, 3))
c = tuple(map(int, color))
cv2.fillPoly(img, [self.points], color=c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With