python - TypeError: Scalar value for argument 'color' is not numeric in openCV -


here code

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)  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) 

i getting error on last line try , pass centroid_color color argument. <type 'numpy.ndarray'> , have been able pass data type cv2.fillpoly color in other instances, not sure why having problem here.

fillpoly() expects iterable, i.e. put cnt in brackets. believe duplicate of https://stackoverflow.com/a/17582850/5818240.

moreover, centroid color variable contains strings. need convert them integers.

centroid_color = np.array((int(centroid_color[0]),int(centroid_color[1]),int(centroid_color[2])))


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -