Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Fill a vector<vector<mat>>

I want to fill a vector<vector<mat>> B with a Mat dest, this matrix will change in a for loop. The problem is B[0][0] is the same that B[last_number][last_numer]. Here is the code:

vector<vector<Mat>> B;
for (int i = 0; i<2; i++) {
    B.push_back(vector<Mat>());
    for (int j = 0; j < 3; j++)
        B[i].push_back(Mat::zeros(10, 10, CV_64F));
}

Mat dest = Mat::ones(10, 10, CV_64F);
for (int i = 0; i<2; i++) {
    for (int j = 0; j < 3; j++)
    {
        dest = 2 * dest;
        B[i][j] = dest;
    }
}

cout << B[0][0];

An this is the output:

[64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64;
 64, 64, 64, 64, 64, 64, 64, 64, 64, 64]