我正在尝试在 opencv 库 (kmeans2) 中应用 kmeans 聚类算法,但每个样本点都有超过 4 个值(超过 4 个特征)
当我尝试使用 cvMat 为 kmeans2 准备参数时,每当我打印或为其分配任何值时,它都会引发异常。
这是我尝试过的两种方法
第一种方法
import cv
from numpy import *
a = zeros([20,1,6])
b = cv.fromarray(a)
print b[0,0]
OpenCV Error: One of arguments' values is out of range (The number of channels must be 1, 2, 3 or 4) in cvRawDataToScalar, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 1531
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: The number of channels must be 1, 2, 3 or 4
第二种方法
import cv
from numpy import *
a = cv.CreateMat(20,1,cv.MAKETYPE(cv.CV_32F,6))
print a[0,0]
OpenCV Error: One of arguments' values is out of range (The number of channels must be 1, 2, 3 or 4) in cvRawDataToScalar, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 1531
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: The number of channels must be 1, 2, 3 or 4
为 kmeans 算法创建和操作 cvMat 参数的正确方法是什么?