Treper
Treper

Reputation: 3653

How to copy a row of a Mat to another Mat's column in OpenCv?

I have two Mat:

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

I want to copy A to B's first column so I use A.copyTo(B.col(0)).But this failed. How to do it?

Upvotes: 5

Views: 6302

Answers (1)

dom
dom

Reputation: 11982

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

But beware, simply assigning one col to another one won't work as you may expect it, because Mat:col just creates a new matrix header for the matrix column you specified and no real copy of the data.

Example code:

B.col( 0 ) = A.col( 0 ); // won't work as expected

A.col( 0 ).copyTo( B.col(0) ); // that's fine

Upvotes: 12

Related Questions