Edge Smoothing and filling inner contours in opencv with iOS

吃可爱长大的小学妹 提交于 2019-12-03 14:12:46

问题


I am trying to tan human skin with different intensity with help of opencv. I have already identified human skin and changing color tone of those pixels. But it is not smooth.

Top left - original image Top right - saturation channel of original image Bottom left - Gray scale mask identifying locations of skin on original image Bottom right - result image with color tone changed of pixels located in mask.

Now my problem is that, in mask image some gap is left because of variation on color tone or brightness in original image. And that is why those portion is missed in result image. Can anyone tell me how can I fill the small gaps in mask image?

Another if someone can help me out for smoothing only edges of my tanned mask will help me a lot. See the reference image below,

Thanks in advance.


回答1:


how about?

morphologyEx(grey,grey,MORPH_CLOSE,getStructuringElement( MORPH_ELLIPSE,Size(7,7)));

although the silhouette gets merged for the left hand

edit:slightly more involved

Mat tmp=grey.clone();
morphologyEx(tmp,tmp,MORPH_GRADIENT,getStructuringElement(MORPH_ELLIPSE,Size(3,3)));
bitwise_not(tmp,tmp);
Mat smallholes=Mat::zeros(tmp.size(), CV_8UC1);
vector<vector<Point>> contours;
findContours(tmp,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
for(int i = 0; i < contours.size(); i++)
{       
    double area = contourArea(Mat(contours[i]));
    if(area<100)
        drawContours(smallholes, contours, i, 255, -1);
}
Mat done;
bitwise_or(grey,smallholes,done);
morphologyEx(done,done,MORPH_CLOSE,getStructuringElement(MORPH_ELLIPSE,Size(3,3)));



来源:https://stackoverflow.com/questions/15806968/edge-smoothing-and-filling-inner-contours-in-opencv-with-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!