Question

I try to directly copying matrix multiplication result to a subset of another matrix:

cv::Mat a,b,c;
//fill matrices a and b and set matrix c to correct size
cv::Mat ab=a*b;
ab.copyTo(c(cv::Rect(0,0,3,3)));

isn' it possible to directly copy the result to matrix c like e.g. (I know this doesn't work):

(a*b).copyTo(c(cv::Rect(0,0,3,3)));
//or 
c(cv::Rect(0,0,3,3)).setTo(a*b);

Wouldn't it be more efficient?

Was it helpful?

Solution

Try this:

cv::Mat subC = c(cv::Rect(0,0,3,3));
subC = a*b;

No copying here.

Or more succinctly:

c(cv::Rect(0,0,3,3)) = a*b;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top