c++ - Find a single approximating boundary for multiple objects in binary image -
an example case of image given below. use binary version of image further processing. contour of object perform shape matching. have written code returns boundary contour given binary image. however, problem arises when image not contain 1 single object case here, can see lower portion of leg palm not attached body. interested in finding contour approximating entire object. so, far opencv has not helped.
my contour function using opencvblobslib library , looks this. detects blobs , filters out small blobs. then, checks see if there 1 contour left. works long objects connected, make robust can handle multiple object case well.
vector<point> getcontour(mat binaryimg) { cblobresult res(binaryimg, mat(),numcores); // possible bounding box using object cblobresult resfiltered; // shall filter bboxes if area less // alpha % of total area double originalimagearea = binaryimg.rows * binaryimg.cols; double alpha = 0.05; double lowerlimitrectarea = alpha * originalimagearea; double bbox_area; for(int = 0; < res.getnumblobs(); i++){ cblob* b = res.getblob(i); rect bbox = b->getboundingbox(); double bbox_area = bbox.area(); if(bbox_area < lowerlimitrectarea){ b->to_be_deleted = 1.0; } } res.filter(resfiltered, b_exclude, cblobgettbdeleted(), b_equal, 1.0,1.0); if (resfiltered.getnumblobs() > 1) { cout << " errror case " << endl; exit(1); } cblob* b = resfiltered.getblob(0); cblobcontour* extcont = b->getexternalcontour(); t_pointlist contpts = extcont->getcontourpoints(); vector<point> contour; contour.resize(contpts.size()); for( int i=0; < contpts.size(); i++) { contour[i] = cv::point(contpts[i].x, contpts[i].y); } return contour; }
Comments
Post a Comment