6 Aralık 2016 Salı

Blob Detection Using OPENCV (C++)


GitHub (https://github.com/mribrahim/Blob-Detection) to download the codes and  contribute the project

A Blob means a group of connected pixels in an image that share near intensity values. In the image below, the goal is to detect the blobs and identify some properties belong to that blobs, as if regionprobs in Python (http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops).

Measure Properties of Regions 

center:                point2f -> Center coordinates of region 
area:                   float -> Number of pixels of region. 
perimeter:          float -> Perimeter of region. 
eccentricity:       float -> Between 1 and 0. (1 for circle) 
solidity:              float -> Between 1 and 0. ( Area / ConvexHullArea ) 
compactness:     float -> Between 1 and 0. ( Area / BoundingRect Area ) -- measure of how close to a rectangle 
mean_intensity:  Vec3b -> mean intensity values of three channel(blue,green,red) of the region 
bounding_box:   Rect -> Bounding box of the region 


Usage of provided Blob Detection Function
Mat image = imread("blobs.jpg");
Mat image_blobs;

namedWindow("Image", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Image", image);

blur(image, image, Size(5, 5));
threshold(image, image_blobs, 200, 255, THRESH_BINARY_INV);

Blob_Detect blob_detect;
vector<Blobs> myblobs = blob_detect.FindBlobs(image,image_blobs);

string str;
for (size_t i = 0; i < myblobs.size(); i++)
{
    str = to_string(myblobs[i].area);
    str = to_string(myblobs[i].eccentricity);
    //str = to_string(myblobs[i].solidity);
    //str = to_string(myblobs[i].compactness);
    //str = to_string(myblobs[i].perimeter);
    //str = to_string(myblobs[i].mean_intensity.val[0]);

    putText(image_blobs, str , cvPoint(myblobs[i].center.x, myblobs[i].center.y), FONT_HERSHEY_SIMPLEX, 0.8, cvScalar(100, 200, 250), 1, CV_AA);
}

namedWindow("Blobs", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Blobs", image_blobs);

Hiç yorum yok:

Yorum Gönder