convert unsigned short mat to vector in opencv <p>I load a depth image in opencv with</p> <pre><code>cv::Mat depth = cv::imread("blabla.png",CV_LOAD_IMAGE_UNCHANGED); </code></pre> <p>then get a subimage of it with</p> <pre><code>cv::Mat sub_image= depth(cv::Rect( roi_x,roi_y,roi_size,roi_size)).clone(); </code></pre> <p>now I want to convert that sub_image into a vector</p> <p>I try with</p> <pre><code>std::vector&lt;uchar&gt; array; array.assign(sub_image.datastart,sub_image.dataend); </code></pre> <p>that found here in StackOverflow in a similar question but it seems it doesnt work properly.</p> <p>The size of array after assignment isnt roi_size * roi_size, but instead roi_size*roi_size*2 </p> <p>Is something wrong with the type of vector?? I also tried various other types like double, float, int, etc</p> <p>The type of the depth image is unsigned short right??</p> <p>Edit:</p> <p>array fills properly (correct size roi_size*roi_size) when I normalize the depth image </p> <pre><code>cv::Mat depthView; cv::normalize(depth, depthView, 0, 255, cv::NORM_MINMAX,CV_8UC1); </code></pre> <p>but thats not what I want to do</p>