Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV文字标签包_Opencv_Svm_K Means_Surf - Fatal编程技术网

OpenCV文字标签包

OpenCV文字标签包,opencv,svm,k-means,surf,Opencv,Svm,K Means,Surf,好的,我正在尝试使用BoW训练一个支持向量机。我在网上找到了一些代码,但找不到一些解释。现在我有这个: string to_string(const int val) { int i = val; std::string s; std::stringstream out; out << i; s = out.str(); return s; } int main() { initModule_nonfree(); P

好的,我正在尝试使用BoW训练一个支持向量机。我在网上找到了一些代码,但找不到一些解释。现在我有这个:

string to_string(const int val) {
    int i = val;
    std::string s;
    std::stringstream out;
    out << i;
    s = out.str();
    return s;
}

int main() {
    initModule_nonfree();

    Ptr<FeatureDetector> detector = FeatureDetector::create("SURF");
    Ptr<DescriptorExtractor> descriptors = DescriptorExtractor::create("SURF");
    Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");

    TermCriteria tc(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 10, 0.001);
    int dictionarySize = 1000;
    int retries = 1;
    int flags = KMEANS_PP_CENTERS;
    BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);

    BOWImgDescriptorExtractor bowDE(descriptors, matcher);


    string dir = "./positive_large", filepath;
    DIR *dp;
    struct dirent *dirp;
    struct stat filestat;

    dp = opendir( dir.c_str() );


    Mat features;
    Mat img;
    vector<KeyPoint> keypoints;
    int i = 0;
    while(dirp = readdir(dp)) {
        filepath = dir + "/" + dirp->d_name;

        cout << "reading: " << filepath << endl;

        if (stat( filepath.c_str(), &filestat )) continue;
        if (S_ISDIR( filestat.st_mode ))         continue;

        img = imread(filepath, 0);

        detector->detect(img, keypoints);
        KeyPointsFilter::retainBest(keypoints, 1000);

        descriptors->compute(img, keypoints, features);
        bowTrainer.add(features);

        drawKeypoints(img, keypoints, img);
        string filenum = to_string(i);
        string filename = "./detected_features/" + filenum + ".png";
        cout << "filename: " << filename << endl;
        imwrite(filename, img);

        i++;
    }

    Mat dictionary = bowTrainer.cluster();
    bowDE.setVocabulary(dictionary);

    return 0;
}
字符串到字符串(const int val){
int i=val;
std::字符串s;
std::stringout;
说出你的名字;

这个问题能为你的问题提供足够的答案吗