title: Opencv c++ detect and crop white region on image
body: <p>I've searched the web nd I already found a few methods to do what I want, but these methods fail in efficiency compared to what I need.</p>
  
  <p>I have a kinect(using Microsoft SDK) which iscurrently acquiring a person removing the background, saving the result in a 3 channel Mat with the person removed from the background. Now I need crop the image to fit only that person, ignoring the black region.</p>
  
  <p>Here's the tricky part: I don't have many time to waste on every operation (I also need to do several other operations and this is supossed to work on real time. What I have currently implemented is a contours finder which give only this region, but it's really slow on real time. Since I only have a white region do detect and that region is really big (50% of the image area) I think there is some faster way to do this, as I only want the minimum and maximum values of x and y of this white area to crop it.</p>
  
  <p>This is my currently my cropping function:</p>
  
  <pre><code>cv::Mat thresh_canny;
  cv::vector&lt;cv::vector&lt;cv::Point&gt; &gt; contours;
  cv::vector&lt;cv::Vec4i&gt; hierarchy;
  cv::threshold(src, thresh_canny, 0, 255, 0);
  cv::Canny(thresh_canny, thresh_canny, 20, 80, 3);
  cv::findContours(thresh_canny, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
  
  if (contours.size() != 1)
      return false;
  
  cv::Rect r = cv::boundingRect(contours.at(0));
  src(r).copyTo(dst);
  return true;
  </code></pre>
  
  <p>Many thanks!!</p>
  
  <p>EDIT: Input image</p>
  
  <p><img src="https://i.stack.imgur.com/QVG2k.jpg" alt="enter image description here"></p>