本文介绍了在OpenCV中更新Mat的子矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV和C ++。我有一个矩阵X这样

I am working with OpenCV and C++. I have a matrix X like this

Mat X = Mat::zeros(13,6,CV_32FC1);

我想更新一个子矩阵4x3的,但我怀疑如何访问矩阵。

and I want to update just a submatrix 4x3 of it, but I have doubts on how to access that matrix in an efficient way.

Mat mat43= Mat::eye(4,3,CV_32FC1);  //this is a submatrix at position (4,4)

推荐答案

最快的方法之一是设置一个标题矩阵指向要更新的列/行的范围,例如this:

One of the quickest ways is setting a header matrix pointing to the range of columns/rows you want to update, like this:

Mat aux = X.colRange(4,7).rowRange(4,8); // you are pointing to submatrix 4x3 at X(4,4)

现在,矩阵到aux(但实际上你会将它复制到X,因为aux只是一个指针):

Now, you can copy your matrix to aux (but actually you will be copying it to X, because aux is just a pointer):

mat43.copyTo(aux);

就是这样。

这篇关于在OpenCV中更新Mat的子矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:23