copy vector of mat to vector of mat

asked 2015-12-18 16:24:36 -0500

ggeo gravatar image

updated 2015-12-19 04:59:03 -0500

(This is related to this )

I have a vector<Mat> src which is filled with data. It's size is src.resize( N )

I have another vector<mat> dest; I am declaring it's size to be dest.resize( N )

1) What is the right way to copy src to dest?Just dest=src?

2) If I want to copy to dest ,only the 1st row and all columns of src vector, then what size the dest vector should be?

dest = src;
src[0]( Range(0, 1),Range::all() ).copyTo( dest[0](Range::all(), Range::all() ) ); //for the 1st array of vector

If ,for example src is 4x4 , then ,since I want to keep only 1st row and all columns,the dest size should be 1x4. Is there a way to do this ?Using the src[0]( Range(0, 1),Range::all() ).copyTo( dest[0](Range::all(), Range::all() ) )?

Or,another idea , is to have the dest the same size with src ,but fill all the rest elements with zero for example?

=====UPDATE================

I figured this:

    dest[0] = src[0 ]( Range(0, 1),Range::all() );

for first row and all columns.

( I can't make it an answer yet ,but if there is another way please share )

edit retag flag offensive close merge delete

Comments

in your code src and dst are vectors of Mat. Using dest.resize( N ) you are creating N Mats so that src[0], src[1]... src[N] are a Mats that are a matrix of pixel.

I suggest to read a bit of docs about Mat, especially = operator .... in addiction there are tons of things and examples already written to learn, like this and this

pklab gravatar imagepklab ( 2015-12-19 05:26:50 -0500 )edit

@pklab:Ok, thanks.

ggeo gravatar imageggeo ( 2015-12-19 05:43:05 -0500 )edit