title: OpenCV 2D-Array to Image Conversion
body: <p>When I tried to convert a 2D array to image, the rows and columns are getting distorted. Same Image cant be made.</p>
  
  <pre><code>using namespace cv;
  using namespace std;
  
  
  int main()
  {
       float val;
       int val1[3][3];
  
       Mat imm = (Mat_&lt;float&gt;(3,3) &lt;&lt; 12, 13, 45, 11, 191, 255, 62, 27, 0);
       if (imm.empty()) //check whether the image is loaded or not
       {
           cout &lt;&lt; "Error : Image cannot be loaded..!!" &lt;&lt; endl;
           //system("pause"); //wait for a key press
           return -1;
       }
  
       for (int y = 0; y &lt; imm.rows; ++y)
       {
           float* row_ptr = imm.ptr&lt;float&gt;(y);
           for (int x = 0; x &lt; imm.cols; ++x)
           {
                val = row_ptr[x];
                val1[y][x]=val;
                if(x%3==0)
                cout&lt;&lt;"\n";
                cout&lt;&lt;val&lt;&lt;"\t";
  
           }
       }
  
  
       Mat out_img(3,3,CV_8U ,val1);
       cout&lt;&lt;"\n\n\n output= "&lt;&lt;out_img;
       cout&lt;&lt;"\n\n\n\n"&lt;&lt;"Input= "&lt;&lt;imm;
   }
  </code></pre>
  
  <p>The output we got is,</p>
  
  <pre><code>12  13  45  
  11  191 255 
  62  27  0   
  
  
   output= [ 12,   0,   0;
     0,  13,   0;
     0,   0,  45]
  
  
  
  Input= [12, 13, 45;
   11, 191, 255;
   62, 27, 0]
  </code></pre>
  
  <p>We can see that output and input were not the same. So need help in reconstruction of the same data.</p>
  
  <p>Thanks.</p>