diff --git a/samples/cpp/BLOB_MSER.cpp b/samples/cpp/BLOB_MSER.cpp index c1854bae5..69446c669 100644 --- a/samples/cpp/BLOB_MSER.cpp +++ b/samples/cpp/BLOB_MSER.cpp @@ -293,38 +293,52 @@ int main(int argc, char *argv[]) void Example_MSER(vector &fileName) { - Mat img(600, 800, CV_8UC1); + Mat img(800, 800, CV_8UC1); fileName.push_back("SyntheticImage.bmp"); map val; - int fond = 255; + int fond = 0; img = Scalar(fond); val[fond] = 1; - Point p[] = { Point(img.cols / 4, img.rows / 4), Point(3 * img.cols / 4, img.rows / 4) }; - for (int j = 0; j<1; j++) - { - for (int i = 1; i &fileName) cumHist.at(i, 0) = cumHist.at(i - 1, 0) + hist.at(i, 0); imwrite(fileName[0], img); cout << "****************Maximal region************************\n"; - for (map::iterator it = val.begin(); it != val.end(); it++) + cout << "i\th\t\tsh\t\tq\n"; + cout << 0 << "\t" << hist.at(0, 0) << "\t\t" << cumHist.at(0, 0) << "\t\t\n"; + for (int i = 1; i < hist.rows-1 ; i++) { - cout << "h" << it->first << "=\t" << hist.at(it->first, 0) << "\t" << cumHist.at(it->first, 0) << "\t\t"; - if (it->first <= 254 && it->first >= 1) + if (cumHist.at(i, 0)>0) { - cout << (cumHist.at(it->first + 1, 0) - cumHist.at(it->first - 1, 0)) / cumHist.at(it->first, 0); + cout << i << "\t" << hist.at(i, 0) << "\t\t" << cumHist.at(i, 0) << "\t\t" << (cumHist.at(i + 1, 0) - cumHist.at(i, 0)) / cumHist.at(i, 0); } + else + cout << i << "\t" << hist.at(i, 0) << "\t\t" << cumHist.at(i, 0) << "\t\t"; cout << endl; } + cout << 255 << "\t" << hist.at(255, 0) << "\t\t" << cumHist.at(255, 0) << "\t\t\n"; cout << "****************Minimal region************************\n"; cumHist.at(255, 0) = hist.at(255, 0); for (int i = 254; i >= 0; i--) cumHist.at(i, 0) = cumHist.at(i + 1, 0) + hist.at(i, 0); - map::iterator it = val.end(); - for (it--; it != val.begin(); it--) + cout << "Minimal region\ni\th\t\tsh\t\tq\n"; + cout << 255-255 << "\t" << hist.at(255, 0) << "\t\t" << cumHist.at(255, 0) << "\t\t\n"; + for (int i = 254; i>=0; i--) { - cout << "h" << it->first << "=\t" << hist.at(it->first, 0) << "\t" << cumHist.at(it->first, 0) << "\t\t"; - if (it->first <= 254 && it->first >= 1) + if (cumHist.at(i, 0)>0) { - cout << (cumHist.at(it->first - 1, 0) - cumHist.at(it->first + 1, 0)) / cumHist.at(it->first, 0); + cout << 255 - i << "\t" << i << "\t" << hist.at(i, 0) << "\t\t" << cumHist.at(i, 0) << "\t\t" << (cumHist.at(i + 1, 0) - cumHist.at(i, 0)) / cumHist.at(i, 0); } + else + cout << 255 - i << "\t" << i << "\t" << hist.at(i, 0) << "\t\t" << cumHist.at(i, 0) << "\t\t"; cout << endl; } // img = imread("C:/Users/laurent_2/Pictures/basketball1.png", IMREAD_GRAYSCALE); @@ -380,10 +400,10 @@ void Example_MSER(vector &fileName) typeDesc.push_back("MSER"); pMSER.push_back(pDefaultMSER); - pMSER.back().delta = 1; + pMSER.back().delta = 1000; pMSER.back().minArea = 1; pMSER.back().maxArea = 180000; - pMSER.back().maxVariation = 500; + pMSER.back().maxVariation = 1.701; pMSER.back().minDiversity = 0; pMSER.back().pass2Only = true; itMSER = pMSER.begin(); @@ -400,11 +420,11 @@ void Example_MSER(vector &fileName) { b = MSER::create(itMSER->delta, itMSER->minArea, itMSER->maxArea, itMSER->maxVariation, itMSER->minDiversity, itMSER->maxEvolution, itMSER->areaThreshold, itMSER->minMargin, itMSER->edgeBlurSize); - b.dynamicCast()->setPass2Only(itMSER->pass2Only); } else { b = MSER::create(itMSER->delta, itMSER->minArea, itMSER->maxArea, itMSER->maxVariation, itMSER->minDiversity); + b.dynamicCast()->setPass2Only(itMSER->pass2Only); } } try { @@ -421,21 +441,21 @@ void Example_MSER(vector &fileName) sbd->detectRegions(img, region, zone); int i = 0; result = Scalar(0, 0, 0); - for (vector::iterator r = zone.begin(); r != zone.end(); r++, i++) - { - // we draw a white rectangle which include all region pixels - rectangle(result, *r, Vec3b(255, 0, 0), 2); - } - i = 0; for (vector>::iterator itr = region.begin(); itr != region.end(); itr++, i++) + { + for (vector ::iterator itp = region[i].begin(); itp != region[i].end(); itp+=2) { - for (vector ::iterator itp = region[i].begin(); itp != region[i].end(); itp++) - { // all pixels belonging to region are red result.at(itp->y, itp->x) = Vec3b(0, 0, 128); - } } } + i = 0; + for (vector::iterator r = zone.begin(); r != zone.end(); r++, i++) + { + // we draw a white rectangle which include all region pixels + rectangle(result, *r, Vec3b(255, 0, 0), 2); + } + } namedWindow(*itDesc + label, WINDOW_AUTOSIZE); imshow(*itDesc + label, result); imshow("Original", img);