OpenCV - how to create Mat from uint8_t pointer
<p>I have the following C++ code:</p>

<pre><code>void foo(const uint8_t* data, int height, int width) {
  // need to create a cv::Mat from *data, which is a pointer to grayscale image data

  // doesn't work correctly (compiles, but array access on the mat leads to a segmentation fault)
  auto img = cv::Mat(height, width, CV_8UC1, &amp;data);

  // how can I fix the line above to create a proper cv::Mat?
}

// I'm calling foo like this
// img is a grayscale image
foo(img.ptr&lt;uint8_t&gt;(0), img.cols, img.rows);
</code></pre>

<p>Could anyone point me on what's wrong with my syntax on creating the matrix inside of foo?</p>