尝试安装OpenCV并遇到尝试导入cv2导致此输出的问题 -
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import
Run Code Online (Sandbox Code Playgroud)
我正在运行Windows 7 x64,Python v 2.7.9谢谢!
我正在运行OpenCV文档中的量化示例代码,它正在抛出
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
Run Code Online (Sandbox Code Playgroud)
这是代码本身:
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) …Run Code Online (Sandbox Code Playgroud)