2
$\begingroup$

I want to select the staff lines as individual blobs in either of these images:

enter image description here enter image description here

Is this possible?

$\endgroup$
5
  • $\begingroup$ May be you should add 1 more image marked by the regions you want to detect! It is very difficult to understand now:( $\endgroup$
    – Balaji R
    Jun 4, 2015 at 5:25
  • $\begingroup$ The regions should be the 5 staff lines. $\endgroup$
    – John
    Jun 4, 2015 at 5:31
  • $\begingroup$ What exactly is staff line? Can you make some marking in paint & upload it? $\endgroup$
    – Balaji R
    Jun 4, 2015 at 5:33
  • $\begingroup$ The regions that I want to select are shown in this image (roughly, I selected them manually): i.imgur.com/4bpZLNJ.png It's ok if other blobs are getting selected too (I can filter them by their area afterwards). $\endgroup$
    – John
    Jun 4, 2015 at 5:40
  • 1
    $\begingroup$ Is it your problem solved? Please mark as answer if this solves your problem. $\endgroup$
    – Balaji R
    Jun 11, 2015 at 6:04

1 Answer 1

2
$\begingroup$

Here is a simple steps in c++ to identify the Objects you want to detect! Hope this solves your problem!


void main()
{
    Mat mSource_Bgr,mSource_Gray,mSmoothed,mEdge,mThres;
    mSource_Bgr= imread(FileName_S.c_str(),IMREAD_COLOR);
    cvtColor(mSource_Bgr,mSource_Gray,COLOR_BGR2GRAY);

    medianBlur(mSource_Gray,mSmoothed,5); /*Just to smooth the Edges*/
/*This is for Automatically calculating the Canny Threshold values*/
    double CannyAccThresh = threshold(mSmoothed,mThres,0,255,CV_THRESH_BINARY|CV_THRESH_OTSU);
    double CannyThresh = 0.1 * CannyAccThresh;

    Canny(mSmoothed,mEdge,CannyThresh,CannyAccThresh); 

    Mat kernal_E,kernal_D;
    int erosion_size=2,dilation_size=2;
    kernal_E= getStructuringElement( MORPH_RECT,Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                                       Point( erosion_size, erosion_size ) );
    kernal_D= getStructuringElement( MORPH_RECT,Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                                       Point( dilation_size, dilation_size ) );
    dilate(mEdge,mEdge,kernal_D);//Just to make sure all the Edges are closed
    erode(mEdge,mEdge,kernal_E);

    imshow("mCanny_Edge",mEdge);
    imwrite(FileName_S+ "mCanny_Edge.bmp",mEdge);

enter image description here

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    /// Find contours
    findContours( mEdge.clone(), contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
    /// Approximate contours to polygons + get bounding rects and circles
    vector<vector<Point> > contours_poly( contours.size() );
    for( size_t i = 0; i < contours.size(); i++ )
    { 
        approxPolyDP( Mat(contours[i]), contours_poly[i], 1, true );
    }

    for (int i = 0; i < contours_poly.size(); i++)
    {
        if(contours_poly[i].size()>100)//Just a filter You can add more here
            drawContours(mSource_Bgr,contours_poly,i,Scalar(0,255,0),2);
    }
    imshow("mResult",mSource_Bgr);

enter image description here }

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.