I have a python image processing function, that uses tries to get the dominant color of an image. I make use of a function I found here https://github.com/tarikd/python-kmea
@Divakar has given a great answer. But if you want to port your own code to OpenCV, then:
img = cv2.imread('image.jpg',cv2.IMREAD_UNCHANGED)
data = np.reshape(img, (-1,3))
print(data.shape)
data = np.float32(data)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
flags = cv2.KMEANS_RANDOM_CENTERS
compactness,labels,centers = cv2.kmeans(data,1,None,criteria,10,flags)
print('Dominant color is: bgr({})'.format(centers[0].astype(np.int32)))
Result for your image:
Dominant color is: bgr([41 31 23])
Time it took: 0.10798478126525879 secs