简体   繁体   中英

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. Is there something I'm overlooking or would I have to implement kmeans by hand?

(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.)

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. Maybe the result will be still better than random initialization. Is there a way to convert an OpenCV Matrix?

Just to conclude this question:

I simply converted the Matrix from 64F to 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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