python - How to read center pixel color -


the input image link : input image

enter image description here

i want read center pixel value of input image shown above , detect color if output color orange print orange. tend error as

  if (center_px == orange):         valueerror: truth value of array more 1 element ambiguous. use a.any() or a.all() 

the code shown

import numpy np import cv2 img = cv2.imread('new bitmap image.bmp') gray = cv2.cvtcolor(img,cv2.color_bgr2gray) ret,thresh = cv2.threshold(gray,100,255,cv2.thresh_binary) contours, hierarchy = cv2.findcontours(thresh,cv2.retr_tree,cv2.chain_approx_simple) cv2.drawcontours(img,contours,-1,(0,0,255),19)  in range(0,len(contours)):     m = cv2.moments(contours[i])     cx = int(m['m10']/m['m00'])     cy = int(m['m01']/m['m00'])     print "centroid = ", cx, ", ", cy      center_px =  img[cx,cy]     print center_px     orange = (0,127,255)      if (center_px == orange):             print "orange" 

i using pyhton , cv2

to test if arrays equal, can use numpy.array_equal

center_px = img[cy, cx] if np.array_equal(center_px, (0, 127, 255)):     print("orange") 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -