5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

K-means in OpenCV

Last updated at Posted at 2012-05-26

STDINから(行)ベクトルの集合を受け取り、STDOUTに中心ベクトルを吐く。

# include <vector>#include <iostream>#include <sstream>#include <opencv2/opencv.hpp>using namespace std;int main(int argc, char** argv){
    int K = 10;    cv::BOWKMeansTrainer trainer(K);    std::string buf;    while(getline(cin, buf)){        stringstream ss(buf);        vector<float> feature;        float v;        while(ss >> v){            feature.push_back(v);        }        trainer.add(cv::Mat_<float>(feature).t());    }    cerr << "#features = " << trainer.descripotorsCount() << endl;    cv::Mat_<float> dictionary = trainer.cluster();    for(int y = 0; y < dictionary.rows; ++y){        for(int x = 0; x < dictionary.cols; ++x){            cout << dictionary(y, x) << "\t";        }        cout << endl;    }}
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?