Mat convert to int array to byte array
I need to convert a Mat to int array and byte array in C ++. How can I do this?
I need to convert a Mat to int array and byte array in C ++. How can I do this?
It is useful to deal with OpenCV's documentation before asking such basic questions. What you need is cv::Mat::convertTo with CV_32S and CV_8U as rtype and if you want to convert 2D matrix to 1D array use cv::Mat::reshape. You can handle Mat as C array with cv::Mat::ptr
// example for 1 channel Mat
cv::Mat img, imgconv;
img.convertTo(imgconv, CV_32S);
if(imgconv.isContinuous() {
imgconv = imgconv.reshape(1, 1);
}
for(int i = 0; i < imgconv.rows; ++i) {
int *ptrarray = imgconv.ptr<int>(i);
for(int ii = 0; ii < imgconv.cols; ++ii) {
int x = ptrarray[ii];
}
}
Asked: 2016-05-30 12:22:27 -0600
Seen: 3,292 times
Last updated: May 30 '16
OpenCV DescriptorMatcher matches
Conversion between IplImage and MxArray
Video On Label OpenCV Qt :: hide cvNamedWindows
Problems using the math.h class with OpenCV (c++, VS2012)
How to reduce false positives for face detection
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images