因为数组auxMat是在内存中连续的,你可以直接从内存复制到您的载体。在这里,你说的是矢量构造使用指针运算从auxMat开始复制,直到结束内存:
std::vector<int> collectionSum(auxMat, auxMat + (gray.rows * gray.cols));
编辑:
对不起,我看了你的问题,作为一维数组(INT *)而不是2D(int **)数组。我诚实地建议切换到一维数组,因为通常它更快,更容易处理。根据是否您使用行优先的顺序或列优先顺序,就可以访问你想要的元素:
elem = y * width + x; // for row-first order
elem = x * height + y; // for column-first order
例如:你有
// Create a 3x3 matrix but represent it continuously as a 1D array
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
const unsigned width = 3;
const unsigned height = 3;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
printf("%d ", A[y * width + x]);
}
printf("\n");
}
到'的push_back()'的值个别。 –