Contour filling with drawContours() fills area inside contours

asked 2017-02-20 08:32:58 -0500

ginister gravatar image

Hi everyone,

I am currently using drawContours() to return a Mat with a hand detected through back projection. However to get the mask from this method I used CV_Filled which fills the Mat after being blurred and finding the contours. However the result is not perfect, and the regions between fingers as shown fill, which is erroneous. What might be a fix for this? I am only using external contours as I don't need the information contained inside the palm.

findContours(bwOut, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
  Mat drawing = Mat::zeros(in.size(), CV_8UC3);

  //Highlight contours (remove CV_FILLED argument for outlines)
  //Results look more realistic as outlines but are more useful as filled.
  for(int i = 0; i gtr than contours.size(); i++){
    Scalar color = *new Scalar(255, 255, 255);
    drawContours(drawing, contours, i, color, CV_FILLED);
  return drawing;


Bryn. image description

edit retag flag offensive close merge delete



To tell what's going on, you should include the same image as just outlines. Otherwise we can't see what's wrong.

Tetragramm gravatar imageTetragramm ( 2017-02-20 20:16:47 -0500 )edit