使用2D数组初始化OpenCV Mat [英] initialize an OpenCV Mat with an 2D array
问题描述
在我的应用程序中,我想创建一个具有某些值的OpenCV Mat A(二维),然后使用A作为输入将其传递给另一个OpenCV函数.
In my application, I want to create a OpenCV Mat A (2-Dimensions) having some values and then pass it to another OpenCV function using A as input.
当前,我正在尝试:
// float data[2][5] = {{1,2,3,4,5},{7,8,9,10,11}};
// OR
float data[10] = {1,2,3,4,5,7,8,9,10,11};
// and then
// A = Mat(1, 5, CV_32FC1, &data, 2); // init from float 1D - array
// OR
A = Mat(2, 5, CV_32FC1, &data, 2);
如果是一维数组,则可以传递值.但这不适用于2D阵列,这是更常见的情况.如何在OpenCV中解决此问题?
in case of 1D array, the value passing is OK. But this does not work for 2D array, which is even more a common case. How can I solve this in OpenCV??
推荐答案
通常,我使用了OpenCV在线指南中的助记符:
orginally, I used the mnemonic from OpenCV online guides:
Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)
但是我不明白"size_t step = AUTO_STEP"是什么意思.这意味着我可以省略"step"参数,OpenCV将使用该参数自动选择AUTO_STEP
But I didn't understand what the document means by "size_t step=AUTO_STEP". And this means that I can ommit 'step' argument with which OpenCV will automatically chooses AUTO_STEP
我已经尝试过,并且可以正常工作:
I've tried and this works:
A = Mat(2, 5, CV_32FC1, &data);
用于从数组初始化的2D Mat
for the 2D Mat initialized from array
这篇关于使用2D数组初始化OpenCV Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!