如何解决我的代码project1.exe已触发断点。发生

时间:2019-03-26 14:32:45

标签: c++ visual-studio-2017

我希望有人帮助我解决我的代码,因为它显示“ project1.exe触发了断点”。我不明白,请帮帮我。在我的代码中,它用于检查测试仪的图片,检查对我有问题的库数据中的所有颜色相似性,因为我明天早上将发送此项目。如果您花了我一点时间,请帮助我。

int main() {

    Mat a[20], b[20], o[20], w[20], r[20], d[20], g[20], m[20], bb[20],rb[20];

    String folderpath0 = "C:/new/Data/Apple/*.jpg";
    String folderpath1 = "C:/new/Data/Banana/*.jpg";
    String folderpath2 = "C:/new/Data/Orange/*.jpg";
    String folderpath3 = "C:/new/Data/Watermelon/*.jpg";
    String folderpath4 = "C:/new/Data/Rose apple/*.jpg";
    String folderpath5 = "C:/new/Data/Durian/*.jpg";
    String folderpath6 = "C:/new/Data/Grapes/*.jpg";
    String folderpath7 = "C:/new/Data/Mango/*.jpg";
    String folderpath8 = "C:/new/Data/Blueberry/*.jpg";
    String folderpath9 = "C:/new/Data/Rambutan/*.jpg";

    vector<String> apple;
    vector<String> banana;
    vector<String> orange;
    vector<String> watermelon;
    vector<String> roseapple;
    vector<String> durian;
    vector<String> grapes;
    vector<String> mango;
    vector<String> blueberry;
    vector<String> rambutan;

    cv::glob(folderpath0, apple);
    cv::glob(folderpath1, banana);
    cv::glob(folderpath2, orange);
    cv::glob(folderpath3, watermelon);
    cv::glob(folderpath4, roseapple);
    cv::glob(folderpath5, durian);
    cv::glob(folderpath6, grapes);
    cv::glob(folderpath7, mango);
    cv::glob(folderpath8, blueberry);
    cv::glob(folderpath9, rambutan);

    for (size_t i = 0; i < apple.size(); i++) {
        a[i] = imread(apple[i]);
        resize(a[i], a[i], Size(600, 450));
    }

    for (size_t i = 0; i < banana.size(); i++) {
        b[i] = imread(banana[i]);
        resize(b[i], b[i], Size(600, 450));
    }

    for (size_t i = 0; i < orange.size(); i++) {
        o[i] = imread(orange[i]);
        resize(o[i], o[i], Size(600, 450));
    }

    for (size_t i = 0; i < watermelon.size(); i++) {
        w[i] = imread(watermelon[i]);
        resize(w[i], w[i], Size(600, 450));
    }

    for (size_t i = 0; i < roseapple.size(); i++) {
        r[i] = imread(roseapple[i]); 
        resize(r[i], r[i], Size(600, 450));
    }

    for (size_t i = 0; i < durian.size(); i++) {
        d[i] = imread(durian[i]);
        resize(d[i], d[i], Size(600, 450));
    }

    for (size_t i = 0; i < grapes.size(); i++) {
        g[i] = imread(grapes[i]);
        resize(g[i], g[i], Size(600, 450));
    }

    for (size_t i = 0; i < mango.size(); i++) {
        m[i] = imread(mango[i]);
        resize(m[i], m[i], Size(600, 450));
    }

    for (size_t i = 0; i < blueberry.size(); i++) {
        bb[i] = imread(blueberry[i]);
        resize(bb[i], bb[i], Size(600, 450));
    }

    for (size_t i = 0; i < rambutan.size(); i++) {
        rb[i] = imread(rambutan[i]);
        resize(bb[i], bb[i], Size(600, 450));
    }

    //TESTER HERE//
    Mat Tester = imread("C:/new/test 10.jpg");
    resize(Tester, Tester, Size(600, 450));
    ///////////////

    vector<Mat> a_bgr[20];
    vector<Mat> b_bgr[20];
    vector<Mat> o_bgr[20];
    vector<Mat> w_bgr[20];
    vector<Mat> r_bgr[20];
    vector<Mat> d_bgr[20];
    vector<Mat> g_bgr[20];
    vector<Mat> m_bgr[20];
    vector<Mat> bb_bgr[20];
    vector<Mat> rb_bgr[20];

    for (size_t i = 0; i < apple.size(); i++) {
        split(a[i], a_bgr[i]);
    }
    for (size_t i = 0; i < banana.size(); i++) {
        split(b[i], b_bgr[i]);
    }
    for (size_t i = 0; i < orange.size(); i++) {
        split(o[i], o_bgr[i]);
    }
    for (size_t i = 0; i < watermelon.size(); i++) {
        split(w[i], w_bgr[i]);
    }
    for (size_t i = 0; i < roseapple.size(); i++) {
        split(r[i], r_bgr[i]);
    }
    for (size_t i = 0; i < durian.size(); i++) {
        split(d[i], d_bgr[i]);
    }
    for (size_t i = 0; i < grapes.size(); i++) {
        split(g[i], g_bgr[i]);
    }
    for (size_t i = 0; i < mango.size(); i++) {
        split(m[i], m_bgr[i]);
    }
    for (size_t i = 0; i < blueberry.size(); i++) {
        split(bb[i], bb_bgr[i]);
    }
    for (size_t i = 0; i < rambutan.size(); i++) {
        split(rb[i], rb_bgr[i]);
    }

    vector<Mat> Tester_bgr;
    split(Tester, Tester_bgr);

    int histSize = 256;

    float ranges[] = { 0,256 };
    const float* histRanges[] = { ranges };

    MatND hist_R, hist_B, hist_G;

    MatND histTest_R, histTest_B, histTest_G;

    double simR, simB, simG, a_x, b_x, o_x, w_x, r_x, d_x, g_x, m_x, bb_x, rb_x;
    double suma[20], sumb[20], sumo[20], sumw[20], sumr[20], sumd[20], sumg[20], summ[20], sumbb[20], sumrb[20];

    calcHist(&Tester_bgr[0], 1, 0, Mat(), histTest_B, 1, &histSize, histRanges, true, false);
    normalize(histTest_B, histTest_B, 0, 1, NORM_MINMAX, -1, Mat());
    calcHist(&Tester_bgr[1], 1, 0, Mat(), histTest_G, 1, &histSize, histRanges, true, false);
    normalize(histTest_G, histTest_G, 0, 1, NORM_MINMAX, -1, Mat());
    calcHist(&Tester_bgr[2], 1, 0, Mat(), histTest_R, 1, &histSize, histRanges, true, false);
    normalize(histTest_R, histTest_R, 0, 1, NORM_MINMAX, -1, Mat());

    for (size_t i = 0; i < apple.size(); i++) {
        calcHist(&a_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&a_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&a_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        suma[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < banana.size(); i++) {
        calcHist(&b_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&b_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&b_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumb[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < orange.size(); i++) {
        calcHist(&o_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&o_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&o_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumo[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < watermelon.size(); i++) {
        calcHist(&w_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&w_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&w_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumw[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < roseapple.size(); i++) {
        calcHist(&r_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&r_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&r_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumr[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < durian.size(); i++) {
        calcHist(&d_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&d_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&d_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumd[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < grapes.size(); i++) {
        calcHist(&g_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&g_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&g_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumg[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < mango.size(); i++) {
        calcHist(&m_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&m_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&m_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        summ[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < blueberry.size(); i++) {
        calcHist(&bb_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&bb_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&bb_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumbb[i] = simR + simB + simG;
    }

    for (size_t i = 0; i < rambutan.size(); i++) {
        calcHist(&rb_bgr[i][0], 1, 0, Mat(), hist_B, 1, &histSize, histRanges, true, false);
        normalize(hist_B, hist_B, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&rb_bgr[i][1], 1, 0, Mat(), hist_G, 1, &histSize, histRanges, true, false);
        normalize(hist_G, hist_G, 0, 1, NORM_MINMAX, -1, Mat());
        calcHist(&rb_bgr[i][2], 1, 0, Mat(), hist_R, 1, &histSize, histRanges, true, false);
        normalize(hist_R, hist_R, 0, 1, NORM_MINMAX, -1, Mat());

        simR = compareHist(hist_R, histTest_R, CV_COMP_CORREL);
        simG = compareHist(hist_G, histTest_G, CV_COMP_CORREL);
        simB = compareHist(hist_B, histTest_B, CV_COMP_CORREL);

        sumrb[i] = simR + simB + simG;
    }

    a_x = suma[0];
    b_x = sumb[0];
    o_x = sumo[0];
    w_x = sumw[0];
    r_x = sumr[0];
    d_x = sumd[0];
    g_x = sumg[0];
    m_x = summ[0];
    bb_x = sumbb[0];
    rb_x = sumrb[0];

    for (size_t i = 0; i < apple.size(); i++) {
        if (a_x <= suma[i]) {
            a_x = suma[i];
        }
    }
    for (size_t i = 0; i < banana.size(); i++) {
        if (b_x <= sumb[i]) {
            b_x = sumb[i];
        }
    }
    for (size_t i = 0; i < orange.size(); i++) {
        if (o_x <= sumo[i]) {
            o_x = sumo[i];
        }
    }
    for (size_t i = 0; i < watermelon.size(); i++) {
        if (w_x <= sumw[i]) {
            w_x = sumw[i];
        }
    }
    for (size_t i = 0; i < roseapple.size(); i++) {
        if (r_x <= sumr[i]) {
            r_x = sumr[i];
        }
    }
    for (size_t i = 0; i < durian.size(); i++) {
        if (d_x <= sumd[i]) {
            d_x = sumd[i];
        }
    }
    for (size_t i = 0; i < grapes.size(); i++) {
        if (g_x <= sumg[i]) {
            g_x = sumg[i];
        }
    }
    for (size_t i = 0; i < mango.size(); i++) {
        if (m_x <= summ[i]) {
            m_x = summ[i];
        }
    }
    for (size_t i = 0; i < blueberry.size(); i++) {
        if (bb_x <= sumbb[i]) {
            bb_x = sumbb[i];
        }
    }
    for (size_t i = 0; i < rambutan.size(); i++) {
        if (rb_x <= sumrb[i]) {
            rb_x = sumrb[i];
        }
    }

    if (a_x > b_x && a_x > o_x && a_x > w_x && a_x > r_x && a_x > d_x && a_x > g_x && a_x > m_x && a_x > bb_x /*&& a_x > rb_x*/) {
        for (size_t i = 0; i < apple.size(); i++) {
            if (a_x == suma[i]) {
                imshow("output", a[i]);
                imshow("Input image", Tester);
                printf("Similarity Apple is %.8f\n", suma[i]);
            }
        }
    }
    if (b_x > a_x && b_x > o_x && b_x > w_x && b_x > r_x && b_x > d_x && b_x > g_x && b_x > m_x && b_x > bb_x /*&& b_x > rb_x*/) {
        for (size_t i = 0; i < banana.size(); i++) {
            if (b_x == sumb[i]) {
                imshow("output", b[i]);
                imshow("Input image", Tester);
                printf("Similarity Banana is %.8f\n", sumb[i]);
            }
        }
    }
    if (o_x > a_x && o_x > b_x && o_x > w_x && o_x > r_x && o_x > d_x && o_x > g_x && o_x > m_x && o_x > bb_x /*&& o_x > rb_x*/) {
        for (size_t i = 0; i < orange.size(); i++) {
            if (o_x == sumo[i]) {
                imshow("output", o[i]);
                imshow("Input image", Tester);
                printf("Similarity Orange is %.8f\n", sumo[i]);
            }
        }
    }
    if (w_x > a_x && w_x > b_x && w_x > o_x && w_x > r_x && w_x > d_x && w_x > g_x && w_x > m_x && w_x > bb_x /*&& w_x > rb_x*/) {
        for (size_t i = 0; i < watermelon.size(); i++) {
            if (w_x == sumw[i]) {
                imshow("output", w[i]);
                imshow("Input image", Tester);
                printf("Similarity Watermelon is %.8f\n", sumw[i]);
            }
        }
    }
    if (r_x > a_x && r_x > b_x && r_x > o_x && r_x > w_x && r_x > d_x && r_x > g_x && r_x > m_x && r_x > bb_x /*&& r_x > rb_x*/) {
        for (size_t i = 0; i < roseapple.size(); i++) {
            if (r_x == sumr[i]) {
                imshow("output", r[i]);
                imshow("Input image", Tester);
                printf("Similarity Rose apple is %.8f\n", sumr[i]);
            }
        }
    }
    if (d_x > a_x && d_x > b_x && d_x > o_x && d_x > w_x && d_x > r_x && d_x > g_x && d_x > m_x && d_x > bb_x /*&& d_x > rb_x*/) {
        for (size_t i = 0; i < durian.size(); i++) {
            if (d_x == sumd[i]) {
                imshow("output", d[i]);
                imshow("Input image", Tester);
                printf("Similarity Durain is %.8f\n", sumd[i]);
            }
        }
    }
    if (g_x > a_x && g_x > b_x && g_x > o_x && g_x > w_x && g_x > r_x && g_x > d_x && g_x > m_x && g_x > bb_x /*&& g_x > rb_x*/) {
        for (size_t i = 0; i < grapes.size(); i++) {
            if (g_x == sumg[i]) {
                imshow("output", g[i]);
                imshow("Input image", Tester);
                printf("Similarity Grapes is %.8f\n", sumg[i]);
            }
        }
    }
    if (m_x > a_x && m_x > b_x && m_x > o_x && m_x > w_x && m_x > r_x && m_x > d_x && m_x > g_x && m_x > bb_x /*&& m_x > rb_x*/) {
        for (size_t i = 0; i < mango.size(); i++) {
            if (m_x == summ[i]) {
                imshow("output", m[i]);
                imshow("Input image", Tester);
                printf("Similarity Mango is %.8f\n", summ[i]);
            }
        }
    }
    if (bb_x > a_x && bb_x > b_x && bb_x > o_x && bb_x > w_x && bb_x > r_x && bb_x > d_x && bb_x > g_x && bb_x > m_x /*&& bb_x > rb_x*/) {
        for (size_t i = 0; i < blueberry.size(); i++) {
            if (bb_x == sumbb[i]) {
                imshow("output", bb[i]);
                imshow("Input image", Tester);
                printf("Similarity Blueberry is %.8f\n", sumbb[i]);
            }
        }
    }
    if (rb_x > a_x && rb_x > b_x && rb_x > o_x && rb_x > w_x && rb_x > r_x && rb_x > d_x && rb_x > g_x && rb_x > m_x && rb_x > bb_x) {
        for (size_t i = 0; i < rambutan.size(); i++) {
            if (rb_x == sumrb[i]) {
                imshow("output", rb[i]);
                imshow("Input image", Tester);
                printf("Similarity Rambutan is %.8f\n", sumrb[i]);
            }
        }
    }


    waitKey(0);

    return 0;

}

0 个答案:

没有答案