cv2.mean not returning result

asked 2015-02-27 10:56:15 -0500

porl gravatar image

Hi! I've been trying to get the mean color of an image using cv2.mean but no matter what I try it only ever returns (0,0,0,0). The code I am using is below, please tell me where I am going wrong.

img = cv2.imread("kungan.jpg")
l = img.shape[1]
h = img.shape[0]
mask = np.zeros((h,l,1), np.uint8)
mean = cv2.mean(img,mask = mask)
print mean
edit retag flag offensive close merge delete



no wonder, if your mask is all 0

what do you need the mask for, actually ?

try without: mean = cv2.mean(img)

berak gravatar imageberak ( 2015-02-27 11:01:47 -0500 )edit

Okay that makes sense however that is what i went with originally and not specifying a mask crashes my program every time. I guess I should just create an appropriate mask.

porl gravatar imageporl ( 2015-03-01 14:12:36 -0500 )edit