An example using the BLOB to detect and filter region.
#include <vector>
#include <map>
#include <iostream>
 
 
 
static void help(char** argv)
{
    cout << "\n This program demonstrates how to use BLOB to detect and filter region \n"
         << "Usage: \n"
         << argv[0]
         << " <image1(detect_blob.png as default)>\n"
         << "Press a key when image window is active to change descriptor";
}
 
 
{
    {
        String inf = 
static_cast<const ostringstream&
>(ostringstream() << pAct.
minArea).str();
 
        String sup = 
static_cast<const ostringstream&
>(ostringstream() << pAct.
maxArea).str();
 
        s = " Area range [" + inf + " to  " + sup + "]";
    }
    {
        if (s.length() == 0)
            s = " Circularity range [" + inf + " to  " + sup + "]";
        else
            s += " AND Circularity range [" + inf + " to  " + sup + "]";
    }
    {
        String inf = 
static_cast<const ostringstream&
>(ostringstream() << (int)pAct.
blobColor).str();
 
        if (s.length() == 0)
            s = " Blob color " + inf;
        else
            s += " AND Blob color " + inf;
    }
    {
        String inf = 
static_cast<const ostringstream&
>(ostringstream() << pAct.
minConvexity).str();
 
        String sup = 
static_cast<const ostringstream&
>(ostringstream() << pAct.
maxConvexity).str();
 
        if (s.length() == 0)
            s = " Convexity range[" + inf + " to  " + sup + "]";
        else
            s += " AND  Convexity range[" + inf + " to  " + sup + "]";
    }
    {
        if (s.length() == 0)
            s = " Inertia ratio range [" + inf + " to  " + sup + "]";
        else
            s += " AND  Inertia ratio range [" + inf + " to  " + sup + "]";
    }
    return s;
}
 
 
 
int main(
int argc, 
char *argv[])
 
{
    if (parser.has("h"))
    {
        help(argv);
        return 0;
    }
    fileName = parser.get<string>("@input");
    Mat img = 
imread(samples::findFile(fileName), IMREAD_COLOR);
 
    if (img.empty())
    {
        cout << "Image " << fileName << " is empty or cannot be found\n";
        return 1;
    }
 
    
    
    vector<String> typeDesc;
    
    vector<SimpleBlobDetector::Params> pBLOB;
    vector<SimpleBlobDetector::Params>::iterator itBLOB;
    
    vector< Vec3b >  palette;
    for (int i = 0; i<65536; i++)
    {
        palette.push_back(
Vec3b(c1, c2, c3));
    }
    help(argv);
 
 
    
    
    typeDesc.push_back("BLOB");    
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByArea = true;
    pBLOB.back().minArea = 1;
    pBLOB.back().maxArea = float(img.rows*img.cols);
    
    typeDesc.push_back("BLOB");
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByArea = true;
    pBLOB.back().minArea = 500;
    pBLOB.back().maxArea = 2900;
    
    typeDesc.push_back("BLOB");
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByCircularity = true;
    
    typeDesc.push_back("BLOB");
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByInertia = true;
    pBLOB.back().minInertiaRatio = 0;
    pBLOB.back().maxInertiaRatio = (float)0.2;
    
    typeDesc.push_back("BLOB");
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByConvexity = true;
    pBLOB.back().minConvexity = 0.;
    pBLOB.back().maxConvexity = (float)0.9;
    
    typeDesc.push_back("BLOB");
    pBLOB.push_back(pDefaultBLOB);
    pBLOB.back().filterByColor = true;
    pBLOB.back().blobColor = 0;
 
    itBLOB = pBLOB.begin();
    vector<double> desMethCmp;
    
    vector<String>::iterator itDesc;
    for (itDesc = typeDesc.begin(); itDesc != typeDesc.end(); ++itDesc)
    {
        vector<KeyPoint> keyImg1;
        if (*itDesc == "BLOB")
        {
            b = SimpleBlobDetector::create(*itBLOB);
            label = Legende(*itBLOB);
            ++itBLOB;
        }
        try
        {
            
            vector<KeyPoint>  keyImg;
            vector<Rect>  zone;
            vector<vector <Point> >  region;
            {
                sbd->detect(img, keyImg, 
Mat());
                int i = 0;
                for (vector<KeyPoint>::iterator k = keyImg.begin(); k != keyImg.end(); ++k, ++i)
                    circle(result, k->pt, (
int)k->size, palette[i % 65536]);
 
            }
            imshow(*itDesc + label, result);
 
        }
        {
            cout << "Feature : " << *itDesc << "\n";
        }
    }
    return 0;
}
Designed for command line parsing.
Definition utility.hpp:890
Class passed to an error.
Definition exception.hpp:86
std::string msg
the formatted error message
Definition exception.hpp:106
n-dimensional dense array class
Definition mat.hpp:951
Class for extracting blobs from an image. :
Definition features.hpp:622
Template class for short numerical vectors, a partial case of Matx.
Definition matx.hpp:379
std::string String
Definition cvstd.hpp:151
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
unsigned char uchar
Definition interface.h:51
#define CV_8UC3
Definition interface.h:101
@ circle
Definition gr_skig.hpp:62
void drawKeypoints(InputArray image, const std::vector< KeyPoint > &keypoints, InputOutputArray outImage, const Scalar &color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
Draws keypoints.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Definition features.hpp:625
float maxCircularity
Definition features.hpp:640
uchar blobColor
Definition features.hpp:634
bool filterByCircularity
Definition features.hpp:639
float maxArea
Definition features.hpp:637
size_t minRepeatability
Definition features.hpp:630
bool filterByColor
Definition features.hpp:633
float minArea
Definition features.hpp:637
float minThreshold
Definition features.hpp:628
float minInertiaRatio
Definition features.hpp:643
float thresholdStep
Definition features.hpp:627
bool filterByArea
Definition features.hpp:636
float minConvexity
Definition features.hpp:646
float minCircularity
Definition features.hpp:640
float maxInertiaRatio
Definition features.hpp:643
float maxConvexity
Definition features.hpp:646
float maxThreshold
Definition features.hpp:629
bool filterByConvexity
Definition features.hpp:645
bool filterByInertia
Definition features.hpp:642
float minDistBetweenBlobs
Definition features.hpp:631