Ask Your Question

Revision history [back]

Fill Mat from 2D vector

I have some code that pulls the pixel values from a mat (image from videocapture):

for (int k = 0; k < rows; k++) {
    for (int l = 0; l < cols; l++) {

        data[k][l] =  (double)<uchar>(k, l);


After some transformations the data is written to file. I am trying to reconstruct the original image using these lines:

  cv::Mat frame(idwt.size(), idwt[0].size(), CV_8UC3);//CV_8UC3 8bit unsigned int 3 channels

for (int k = 0; k < idwt.size(); k++) {
    for (int l = 0; l < idwt[k].size(); l++) {

<uchar>(k, l) = (unsigned char)std::round(idwt[k][l]); 

Where the data is in idwt, declared as :

 std::vector<std::vector<double>> idwt(row, std::vector<double>(col));

I've inspected the original mat data, the transformed data and the reconstructed data and there is no error but I get a partial reconstructed image. (I have some links to related questions but not enough karma now to post). I cannot fathom why this fails in this way, I've read the docs and nothing seems like a solution to this.