[Fix] Fix palette generation on opencv-3.x ()

pull/1797/head
Li Zhang 2023-02-17 18:33:38 +08:00 committed by GitHub
parent 02d5a09989
commit b1be9c67f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions
demo/csrc/cpp/utils

View File

@ -79,9 +79,11 @@ inline Palette Palette::get(int n) {
for (auto& x : samples) {
x = {(float)uniform_dist(gen), (float)uniform_dist(gen), (float)uniform_dist(gen)};
}
std::vector<cv::Point3f> centers;
cv::kmeans(samples, n, indices, cv::TermCriteria(cv::TermCriteria::Type::COUNT, 10, 0), 1,
cv::KMEANS_PP_CENTERS, centers);
std::vector<cv::Point3f> centers(n);
cv::Mat c_mat(centers, false);
cv::Mat s_mat(samples, false);
cv::kmeans(s_mat, n, indices, cv::TermCriteria(cv::TermCriteria::Type::COUNT, 10, 0), 1,
cv::KMEANS_PP_CENTERS, c_mat);
Palette p;
for (const auto& c : centers) {
p.data.emplace_back((uchar)c.x, (uchar)c.y, (uchar)c.z);