Ask Your Question
0

GetRow returns Mat, clone or original data?

asked 2014-02-16 03:24:08 -0500

MRDaniel gravatar image

Hello,

Are these two pieces of code equivalent? SDMat and BMat are the rows of the matrices SD and B. SDMat and BMat interact, thus changing the original SD and B matrices.

Old version

for(i = 0; i < __shape.nModes()+4; i++) { for(j = 0; j < __texture.nModes(); j++) { cvGetRow(SD, &SDMat, i); cvGetRow(B, &BMat, j); cvScaleAdd(&BMat, cvScalar(-cvmGet(V,i,j)), &SDMat, &SDMat); } }

New version.

for(i = 0; i < __shape.nModes()+4; i++) { for(j = 0; j < __texture.nModes(); j++) { SDMat = SD.row(i); BMat = B.row(j); cv::scaleAdd(BMat, -V.at<double>(i,j), SDMat, SDMat); } }

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-16 06:06:33 -0500

updated 2014-02-16 06:45:54 -0500

I think your two pieces of code are not the same: while cvGetRow(SD, &SDMat, i);cvGetRow(B, &BMat, j); statements copy row i of SD to SDMat and row j of B to BMat, the two statements SDMat = SD.row(i); BMat = B.row(j); do not. Method row(int) of the Mat class only return matrix header whose pointer data points to a specific row of original object, it does not make the copy as you want it to do (if you mean it). You can see more at http://docs.opencv.org/modules/core/doc/basic_structures.html.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-02-16 03:24:08 -0500

Seen: 220 times

Last updated: Feb 16 '14