我一直在研究MNIST数据集来分类手写数字图像。我可以读取图像并计算它们的直方图。然后,我将Mat的直方图推回到矢量中。由于方法(InputArray)的第一个参数导致一些错误,我无法实现K-Means聚类算法方法(kmeans())OpenCV中K-Means聚类方法的输入数据类型(向量<Mat>)
已使用OpenCV 3.0。
vector<Mat> histogram_list;
//some implementations
int clusterCount = 10;
Mat labels, centers;
int attempts = 5;
kmeans(samplingHist(histogram_list, h_bins, s_bins), clusterCount, labels,
TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10000, 0.0001),
attempts, KMEANS_PP_CENTERS, centers);
有没有什么建议可以解决这个问题?
编辑:
mat.int.hpp文件。关于断言的错误失败了......并且它将我返回到那段代码。
template<typename _Tp> inline_Tp& Mat::at(int i0, int i1) {
CV_DbgAssert(dims <= 2);
CV_DbgAssert(data);
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
return ((_Tp*)(data + step.p[0] * i0))[i1];
}
我尝试用采样从载体垫子上解决问题。然而它无法帮助解决它。我在哪里犯了一个错误?
Mat samplingHist(vector<Mat> &vec, int h, int s) {
Mat samples(vec.size(), h * s, CV_32F);
for (int k = 0; k < vec.size(); k++)
for (int y = 0; y < h; y++)
for (int x = 0; x < s; x++)
samples.at<float>(k, y* s + x) = vec[k].at<float>(y, x);
return samples;
}
什么错误? –
您正在使用哪种opencv版本? – Rama