OpenCV - How to apply Kmeans on a grayscale image?
问题 I am trying to cluster a grayscale image using Kmeans. First, I have a question: Is Kmeans the best way to cluster a Mat or are there newer more efficient approaches? Second, when I try this: Mat degrees = imread("an image" , IMREAD_GRAYSCALE); const unsigned int singleLineSize = degrees.rows * degrees.cols; Mat data = degrees.reshape(1, singleLineSize); data.convertTo(data, CV_32F); std::vector<int> labels; cv::Mat1f colors; cv::kmeans(data, 3, labels, cv::TermCriteria(cv::TermCriteria::EPS