Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It is not possible to initialize Mat with vector of vectors. Main reason is that by default Mat(vector) does not perform copy of data. This is just a header that points to contents of the vector itself. It can be done because content of vector is continious in memory. This can't be done with vector of vectors because content of each sub-vector may be in different place in memory and so it must be copied in order to create Mat.

It is possible to initailize Mat with NumType as long as it is legal type for Mat:

Mat_<NumType> mtx(vect.size(),vect[0].size());

Also more effective way of coping data to mtx is:

for(int i=0; i<vect.size(); i++)
{     
    if (vect[0].size() != vect[i].size())
         // throw some error        
    memcpy(mtx.ptr(i), &(vect[i][0]), vect[i].size()*sizeof(NumType));   
}