Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

counting blue pixels in image python

hello I am try to calculate blue pixels in image every time I run the code I got zero so anyone help me this is my code

    import cv2
import numpy as np

img = cv2.imread("mm.jpg")
BLUE_MIN = np.array([0, 0, 200], np.uint8)
BLUE_MAX = np.array([255, 50, 50], np.uint8)

dst = cv2.inRange(img, BLUE_MIN, BLUE_MAX)
no_blue = cv2.countNonZero(dst)
print('The number of blue pixels is: ' + str(no_blue))
cv2.namedWindow("opencv")
cv2.imshow("opencv",img)
cv2.waitKey(0)
click to hide/show revision 2
retagged

updated 2013-11-02 06:16:36 -0600

berak gravatar image

counting blue pixels in image python

hello I am try to calculate blue pixels in image every time I run the code I got zero so anyone help me this is my code

    import cv2
import numpy as np

img = cv2.imread("mm.jpg")
BLUE_MIN = np.array([0, 0, 200], np.uint8)
BLUE_MAX = np.array([255, 50, 50], np.uint8)

dst = cv2.inRange(img, BLUE_MIN, BLUE_MAX)
no_blue = cv2.countNonZero(dst)
print('The number of blue pixels is: ' + str(no_blue))
cv2.namedWindow("opencv")
cv2.imshow("opencv",img)
cv2.waitKey(0)