Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In any case you can try the following:

//create Mat from vector vector<uchar> vec; // vector with your data int rows = 3; int cols = 4;

if(vec.size() == rowscols) // check that the rows and cols match the size of your vector { Mat m = Mat(rows, cols, CV_8UC1); // initialize matrix of uchar of 1-channel where you will store vec data //copy vector to mat memcpy(m.data, vec.data(), vec.size()sizeof(uchar)); // change uchar to any type of data values that you want to use instead }

the above code should do the trick.

In any case you can try the following:

//create Mat from vector
vector<uchar> vec; // vector with your data
int rows = 3;
int cols = 4;

4;

if(vec.size() == rowscols) rows*cols) // check that the rows and cols match the size of your vector { Mat m = Mat(rows, cols, CV_8UC1); // initialize matrix of uchar of 1-channel where you will store vec data //copy vector to mat memcpy(m.data, vec.data(), vec.size()sizeof(uchar)); vec.size()*sizeof(uchar)); // change uchar to any type of data values that you want to use instead }

}

the above code should do the trick.