OpenCV Skin Detection

I am defining the skin, but cannot get smooth. The image below contains the input (left) and the output (right) using the code also attached below. Now the desired result was to be the bottommost image (the one that is smooth along the edges and has no holes inside). How to achieve this result? Sample code to get you started will be very helpful.

Input (left) and wrong output (right):

enter image description here

Required Conclusion:

enter image description here

Code for generating Incorect output:

#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; int main(){ Mat src = imread("qq.jpg"); if (src.empty()) return -1; blur( src, src, Size(3,3) ); Mat hsv; cvtColor(src, hsv, CV_BGR2HSV); Mat bw; inRange(hsv, Scalar(0, 10, 60), Scalar(20, 150, 255), bw); imshow("src", src); imshow("dst", bw); waitKey(0); return 0; } 

Changed code (after Astor's suggestion): (now the problem: how do you smooth out the output?)

 #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; int findBiggestContour(vector<vector<Point> >); int main(){ Mat src = imread("qq.jpg"); if (src.empty()) return -1; blur( src, src, Size(3,3) ); Mat hsv; cvtColor(src, hsv, CV_BGR2HSV); Mat bw; inRange(hsv, Scalar(0, 10, 60), Scalar(20, 150, 255), bw); imshow("src", src); imshow("dst", bw); Mat canny_output; vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours( bw, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) ); int s = findBiggestContour(contours); Mat drawing = Mat::zeros( src.size(), CV_8UC1 ); drawContours( drawing, contours, s, Scalar(255), -1, 8, hierarchy, 0, Point() ); imshow("drw", drawing); waitKey(0); return 0; } int findBiggestContour(vector<vector<Point> > contours){ int indexOfBiggestContour = -1; int sizeOfBiggestContour = 0; for (int i = 0; i < contours.size(); i++){ if(contours[i].size() > sizeOfBiggestContour){ sizeOfBiggestContour = contours[i].size(); indexOfBiggestContour = i; } } return indexOfBiggestContour; } 
+8
c ++ opencv flood-fill skin
source share
2 answers

You must use findContours to determine the largest path after this path drawn by the path, with a fill parameter of -1, using the drawContours method. Here's a useful link: http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html

+9
source share

To improve the smoothness of the output or, in other words, reduce black holes in the detected area, try to perform morphological operations on the resulting image. The following documentation explains the erosion and extension functions in opencv. http://docs.opencv.org/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html

+1
source share

All Articles