当前位置: 首页>>代码示例>>C++>>正文


C++ Analyser::compareToHistogram方法代码示例

本文整理汇总了C++中Analyser::compareToHistogram方法的典型用法代码示例。如果您正苦于以下问题:C++ Analyser::compareToHistogram方法的具体用法?C++ Analyser::compareToHistogram怎么用?C++ Analyser::compareToHistogram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Analyser的用法示例。


在下文中一共展示了Analyser::compareToHistogram方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processImage

Leaf processImage(string currentImgName) {
    
    Leaf newLeaf;
    newLeaf.path = "";
    newLeaf.filename = "";
    newLeaf.filenameProcessed = "";
    newLeaf.filenameSegmented = "";
    newLeaf.isSick = false;
    newLeaf.sicknessLevel = 0.0;
    
    // on sépare le chemin et le nom de l'image
    string tmp = string(currentImgName);
    while (tmp[tmp.length()-1] != '/') {
        newLeaf.filename = tmp[tmp.length()-1] + newLeaf.filename;
        //tmp.pop_back();
        tmp = tmp.substr(0,tmp.length()-1);
    }
    newLeaf.path = tmp;
    
    // on supprime l'extension de l'image
    tmp = string(newLeaf.filename);
    while (tmp[tmp.length()-1] != '.')
        tmp = tmp.substr(0,tmp.length()-1);
        //tmp.pop_back();
    //tmp.pop_back();
    tmp = tmp.substr(0,tmp.length()-1);
    
    // on crée les noms des nouvelles images
    newLeaf.filenameProcessed = tmp + "_processed.jpg";
    newLeaf.filenameSegmented = tmp + "_segmented.jpg";
    
    cout << "Loading: " << newLeaf.path << newLeaf.filename << endl;
    
    string dataPath = "../data/";
    
    Analyser analyser;
    string histogramName = dataPath + "leafsample.png";
    Mat leafHisto = analyser.getHSHistogram(histogramName);
    histogramName = dataPath + "injuredsample.png";
    Mat injuriesHisto = analyser.getHSHistogram(histogramName);
    cout << "loaded histogram" << endl;
    
    
    Mat currentImg = imread(currentImgName, CV_LOAD_IMAGE_UNCHANGED);
    
    if (currentImg.empty()) //check whether the image is loaded or not
    {
        cout << "Error : Image cannot be loaded..!!" << endl;
        //system("pause"); //wait for a key press
        return newLeaf;
    }
    
    Mat origImg = currentImg;
    
    // La comparaison d'histogramme nous permet de faire un masque de probabilité
    Mat leafMask;
    analyser.compareToHistogram(origImg, leafHisto, leafMask);
    
    // Segmentation de la feuille
    Mat leafImg;
    analyser.segmentLeaf(origImg, leafMask, leafImg);
    
    // La détection de contours nous permet de faire ressortir les irrégularités
    Mat detailedEdges, coarseEdges;
    analyser.detectEdges(leafImg, detailedEdges, coarseEdges);
    Mat leafIrregularities;
    analyser.detectIrregularities(detailedEdges, coarseEdges, leafIrregularities);
    
    float irregularityScore = analyser.computeIrregularityScore(leafIrregularities, leafMask);
    
    // La comparaison d'histogramme nous permet de faire un masque de probabilité
    Mat injuriesMask;
    analyser.compareToHistogram(leafImg, injuriesHisto, injuriesMask);
    
    // Segmentation de la feuille
    Mat injuriesImg;
    analyser.segmentLeaf(origImg, injuriesMask, injuriesImg);
    
    float injuriesScore = analyser.computeInjuriesScore(injuriesImg, injuriesMask);
    
    float illnessScore = irregularityScore * injuriesScore * 100;
    
    cout << "injuriesScore: " << injuriesScore << endl;
    cout << "irregularityScore: " << irregularityScore << endl;
    cout << "score: " << illnessScore << endl;
    
    if (illnessScore > 0.5 && injuriesScore > 0.1) {
        cout << "Leaf is sick " << injuriesScore*100 << "%." << endl;
        newLeaf.isSick = true;
        newLeaf.sicknessLevel = injuriesScore*100;
    } else {
        cout << "Leaf is not sick." << endl;
    }
        
    Mat finalImg = analyser.createInfoImage(leafImg, leafMask, leafIrregularities);
    
    
    //outfilename = outfileprefix + "_processed.jpg";
    imwrite(newLeaf.path + newLeaf.filenameProcessed, finalImg);
    
//.........这里部分代码省略.........
开发者ID:niclupien,项目名称:leaf-me-alone-mtl,代码行数:101,代码来源:main.cpp


注:本文中的Analyser::compareToHistogram方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。