使用小数组制作长向量(列矩阵)

Making a long vector(coloumn Matrix) using small arrays

本文关键字:向量 小数 数组      更新时间:2023-10-16

我正在尝试制作一个包含数组元素的向量(特征向量)。

假设我在第一次迭代中有一个大小为 nx1 的数组arr1。我必须将此数组元素添加到大小CvMat矩阵featureVect中,2*n x 1 .

在下一次迭代中,我有一个大小为 nx1 的数组arr2,现在我必须将此数组添加到从第 n+1 行到2*n featureVect(使用基于一的索引)

假设我有

int arr1[4] = {1, 2, 3, 4};
int arr2[4] = {5, 6, 7, 8};
CvMat *featureVect; 

现在我希望结果看起来像这样(其中featureVect是单列矩阵)

featureVect = {1, 2, 3, 4, 5, 6, 7, 8};// featureVect size is 8x1;

如果你在OpenCV中使用C++,我会推荐Mat类。然后

Mat featureVect(8,1,CV_32S); //CV_32s <=> int (32-bit signed integer)
const int n = 4;
for(int i = 0; i < n; ++i) 
{
   featureVect.at<int>(i,0)     = arr1[i];
   featureVect.at<int>(i+n,0) = arr2[i];
}