How to copy Mat row to another Mat column in OpenCv?

I have two Mat:

A: size(1,640) B: size(640,480) 

I want to copy the first column of A to B, so I use A.copyTo(B.col(0)) . But that failed. How to do it?

+4
source share
1 answer

You were on the right track! Mat:col is a match tool to use :)

But be careful, simply assigning one col to another will not work as you might expect, because Mat:col just creates a new matrix header for the specified matrix column and no real copy of the data.

Code example:

 B.col( 0 ) = A.col( 0 ); // won't work as expected A.col( 0 ).copyTo( B.col(0) ); // that fine 
+10
source

All Articles