title: How to convert 16 bit image to 8 bit in OpenCV C++
body: <p>I'm stuck at using <code>connectedComponents</code> function.</p>
  
  <pre><code>const uint16_t* depth_frame_data = (const uint16_t*)(rs2_get_frame_data(frame, &amp;e));
  Mat image(Size(WIDTH, HEIGHT), CV_16UC1, (void *)depth_frame_data, Mat::AUTO_STEP);
  threshold(image, image_th, one_meter, 255, THRESH_BINARY_INV);
  </code></pre>
  
  <p>I thought this is enough for <code>connectedComponents</code>, but i just realized i should input binary Matrix :</p>
  
  <pre><code>Mat image_bin(image_th, true);
  image_bin.convertTo(image_bin, CV_8U, 0.00390625);
  </code></pre>
  
  <p>But when i build it,</p>
  
  <blockquote>
    <p>OpenCV(3.4.2) Error: Assertion failed ...</p>
  </blockquote>