title: Face mask in opencv
body: <p><strong>Input:</strong> face image </p>
  
  <p><strong>Problem:</strong> thresholded image before applying Canny to find contours but does not return face mask</p>
  
  <p><strong>Desired output</strong> if different face is input,it should generate a proper face mask(face area white and background white)</p>
  
  <p>Tried with apple picture..works fine</p>
  
  <pre><code>            #include &lt;opencv2/highgui/highgui.hpp&gt;
              #include &lt;opencv2/core/core.hpp&gt;
              #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  
              using namespace cv;
              using namespace std;
  
              int main(){
                Mat right=imread("front.jpg");
                Mat img1;
                cvtColor(right, img1, CV_RGB2GRAY);
                threshold(img1,img1,160,255,cv::THRESH_BINARY);
                Canny(img1, img1, 128, 350);
                vector&lt; vector&lt;Point&gt; &gt; contours;
                findContours(img1, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
                Mat mask = Mat::zeros(img1.rows, img1.cols, CV_8UC1);
                drawContours(mask, contours, -1, Scalar(255), CV_FILLED);
                normalize(mask.clone(), mask, 0.0, 255.0, CV_MINMAX, CV_8UC1);
  
                imshow("original", right);
                imshow("thresh",img1);
                imshow("mask", mask);
  
                waitKey(0);
                return 0;
      }
  </code></pre>
  
  <p>Here is the image that I used</p>
  
  <p><img src="https://i.stack.imgur.com/TNkah.jpg" alt="enter image description here"></p>
  
  <p><em>Please ignore the first 3 comments below</em></p>