What is the best way to use the OpenCV library in conjunction with the Armadillo library?

不想你离开。 提交于 2019-12-05 17:47:21

To avoid or reduce copying, you can access the memory used by Armadillo matrices via the .memptr() member function. For example:

mat X(5,6);
double* mem = X.memptr();

Be careful when using the above, as you're not allowed to free the memory yourself (Armadillo will still manage the memory).

Alternatively, you can construct an Armadillo matrix directly from existing memory. For example:

double* data = new double[4*5];
// ... fill data ...
mat X(data, 4, 5, false);  // 'false' indicates that no copying is to be done; see docs

In this case you will be responsible for manually managing the memory.

Also bear in mind that Armadillo stores and accesses matrices in column-major order, ie. column 0 is first stored, then column 1, column 2, etc. This is the same as used by MATLAB, LAPACK and BLAS.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!