简体   繁体   English

使用CV_64F1的OpenCV kmeans

[英]OpenCV kmeans with CV_64F1

According to the docs and the error that I get: 根据文档和我得到的错误:

OpenCV Error: Assertion failed (data.dims <= 2 && type == CV_32F && K > 0)

OpenCV's kmeans clustering doesn't support CV_64F1 typed Arrays. OpenCV的kmeans群集不支持CV_64F1类型的数组。 Is there something I'm overlooking or would I have to implement kmeans by hand? 我有什么要忽略的吗?还是我必须手工实施kmeans?

(I'm using OpenCV 3.1.0 C++ Intefaces with gcc 5.3.1 on Linux; and yes, I need the 64 Bit precision, I'm doing some machine learning data analysis.) (我在Linux上使用带有gcc 5.3.1的OpenCV 3.1.0 C ++ Intefaces;是的,我需要64位精度,正在做一些机器学习数据分析。)

Edit: On second thought, it would be worth a try to "down cast" the Matrix to 32F, since I only need the k-means clustering to initialize my factors for the NMF. 编辑:再三考虑,将矩阵“降频”到32F值得尝试,因为我只需要k-均值聚类即可为NMF初始化因子。 Maybe the result will be still better than random initialization. 也许结果仍然比随机初始化更好。 Is there a way to convert an OpenCV Matrix? 有没有办法转换OpenCV矩阵?

Just to conclude this question: 总结一下这个问题:

I simply converted the Matrix from 64F to 32F: 我只是将Matrix从64F转换为32F:

cv::Mat a32f;
a.convertTo(a32f, CV_32FC1);

kmeans(a32f,k, labels,
    cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::COUNT , 10, .0001),
    5, cv::KMEANS_RANDOM_CENTERS);

with a being a parameter of type cv::Mat CV_64FC1 a为式CV的参数::垫CV_64FC1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM