1 | initial version |
Check Mat doc for details
BTW, you have to be sure that there is enough space in destination than... for a single row you can use assignment like this
if(dstMat.cols==srcMat.cols)
dstMat.row(5) = srcMat.row(1); //copy src 2nd row to dst 6th
In general you can use ROI like here
Rect srcRect(0,1,srcMat.cols,1); //select 2nd row
Rect dstRect(0,5,srcMat.cols,1); //select 6th row
dstRect = dstRect & Rect(0,0,dstMat.size() ) ; //intersection to avoid out of range
srcMat(srcRect).copyTo(dstMat(dstRect));
as alternative you can use Range
srcMat.rowRange(1,2).copyTo(dstMat.rowRange(5, 6) ); //copy src 2nd row to dst 6th row
or more general range
//copy src 2nd row to dst 6th row
srcMat( Range(1, 2),Range::all() ).copyTo( dstMat(Range(5, 6), Range::all() ) )
2 | No.2 Revision |
Check Mat doc for details
BTW, you have to be sure that there is enough space space(size and data type) in destination than...
destination.
Check for data type
if (srcMat.type() != dstMat.type())
return;
for a single row you can use assignment like this
if(dstMat.cols==srcMat.cols) below (this
will not work)dstMat.row(5) =srcMat.row(1); //copy srcsrcMat.row(1)if (srcMat.cols == dstMat.cols) srcMat.row(1).copyTo(dstMat.row(5)); //copy the 2nd row to
dst 6ththe 6th rowIn general you can use ROI like here
Rect
srcRect(0,1,srcMat.cols,1);srcRect(Point(0, 1), Size(srcMat.cols, 1)); //selectthe 2nd row RectdstRect(0,5,srcMat.cols,1); //select 6th rowdstRect(Point(3, 5), srcRect.size() ); //destination in (3,5), size same as srcRect dstRect = dstRect &Rect(0,0,dstMat.size() ) ;Rect(Point(0, 0), dstMat.size()); //intersection to avoid out of rangesrcMat(srcRect).copyTo(dstMat(dstRect));srcRect = Rect(srcRect.tl(), dstRect.size()); //adjust source size same as safe destination srcMat(srcRect).copyTo(dstMat(dstRect)); //copy from (0,1) to (3,5) max allowed cols
As alternative you can use Range
srcMat.rowRange(1,2).copyTo(dstMat.rowRange(5, 6) ); //copy src 2nd row to dst 6th row
or rowRange
if (srcMat.cols == dstMat.cols)
srcMat.rowRange(1, 2).copyTo(dstMat.rowRange(5, 6)); //copy row: 2nd->6th
Or more general range
//copy src Range colRange = Range(0, min(srcMat.cols, dstMat.cols)); //select maximum allowed cols
//copy the 2nd row to dst the 6th row
srcMat( Range(1, 2),Range::all() ).copyTo( dstMat(Range(5, row max allowed cols
srcMat(Range(1, 2), colRange).copyTo(dstMat(Range(5, 6), Range::all() ) )
colRange));