我有一个python图像处理函数,它使用try 获取图像的主色.我使用了我在这里找到的一个函数
它是有效的,但不幸的是,我不太明白它的作用,我了解到np.histogram
相当慢,我应该使用cv2.calcHist
,因为它比https://docs.opencv.org/trunk/d1/db7/tutorial_py_histogram_begins.html快40倍
我想了解如何更新代码以使用cv2.calcHist
或更好的值,我必须输入哪些值.
我的职能
def centroid_histogram(clt):
# grab the number of different clusters and create a histogram
# based on the number of pixels assigned to each cluster
num_labels = np.arange(0, len(np.unique(clt.labels_)) + 1)
(hist, _) = np.histogram(clt.labels_, bins=num_labels)
# normalize the histogram, such that it sums to one
hist = hist.astype("float")
hist /= hist.sum()
# return the histogram
return hist
clt
中的pprint
是这个,不确定这是否有用
KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,
n_clusters=1, n_init=10, n_jobs=1, precompute_distances='auto',
random_state=None, tol=0.0001, verbose=0)
我的代码可以在这里找到:https://github.com/primus852/python-movie-barcode
非常感谢初学者的帮助.
根据要求:
样本图像
最主要的 colored颜色 :
rgb(22,28,37)
直方图的计算时间:
0.021515369415283203s