【问题标题】:OpenCV quantization sample code not runningOpenCV量化示例代码未运行
【发布时间】:2015-01-27 20:45:29
【问题描述】:

我正在运行找到in the OpenCV documentation的量化示例代码,它正在抛出

Traceback (most recent call last):
File "QuantizeTest.py", line 13, in <module>
ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
TypeError: an integer is required

这是代码本身:

import numpy as np
import cv2

img = cv2.imread('Sample.jpg')
Z = img.reshape((-1,3))

# convert to np.float32
Z = np.float32(Z)

# define criteria, number of clusters(K) and apply kmeans()
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
K = 8
ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)

# Now convert back into uint8, and make original image
center = np.uint8(center)
res = center[label.flatten()]
res2 = res.reshape((img.shape))

cv2.imshow('res2',res2)
cv2.waitKey(0)
cv2.destroyAllWindows()

任何帮助将不胜感激!

【问题讨论】:

    标签: python opencv k-means quantization


    【解决方案1】:

    变化:

    ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
    

    到:

    ret,label,center=cv2.kmeans(Z,K,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
    

    (已删除None

    【讨论】:

      猜你喜欢
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2012-09-08
      • 2017-01-26
      • 1970-01-01
      相关资源
      最近更新 更多