title: opencv error multiplying 2 Mat's
body: <p>I am multiplying 2 matrices (Mat objects) in opencv.</p>
  
  <p>Here is how first Mat was generated :</p>
  
  <pre><code>cv::Mat R(m, k, CV_8UC1);
  rm.generateRandomMatrix(m, k, 255, R);
  </code></pre>
  
  <p>Here is how the second one was generated: </p>
  
  <pre><code>for (int i=0; i&lt;=n; i++)
  {
      randomMatrix_Xi rm;
      cv::Mat Xi(k, 1, CV_8UC1);
      rm.generateRandomMatrix(k, 1, 255, Xi);
      random_Xi_Vectors.push_back(Xi);
      sleep(2);
  }
  </code></pre>
  
  <p>Here is the generateRandomMatrix() function definition which I have used in both places: </p>
  
  <pre><code>int randomMatrix_Xi::generateRandomMatrix(int m, int k, int range, cv::Mat R)
  {
      typedef boost::mt19937 RNGType;
      RNGType rng(std::time(0));
      boost::uniform_int&lt;&gt; one_to_range( 1, range);
      boost::variate_generator&lt; RNGType, boost::uniform_int&lt;&gt; &gt; number_generator(rng, one_to_range);
      for (int j=0; j&lt;k; j++)
      {
          for ( int i = 0; i &lt; m; i++ ) 
          {
             int n = number_generator();
             R.at&lt;uchar&gt;(i,j) = n;
             //std::cout&lt;&lt;"Putting "&lt;&lt;n&lt;&lt;" at"&lt;&lt;i&lt;&lt;", "&lt;&lt;j&lt;&lt;std::endl;
          }
      }
  }
  </code></pre>
  
  <p>Finally, here is the place where I am doing the multiplication of the two Mat's:</p>
  
  <pre><code>for (int i = 0; i &lt; n; i++)
      {
          std::cout&lt;&lt;" Sizes of matrices to be multiplied: "&lt;&lt;std::endl;
  
          cv::Size Xi_size = random_Xi_Vectors[i].size();
          cv::Size A_size = R.size();
          std::cout&lt;&lt;"R : "&lt;&lt;A_size.height&lt;&lt;" "&lt;&lt;A_size.width&lt;&lt;std::endl;
          std::cout&lt;&lt;"Xi : "&lt;&lt;Xi_size.height&lt;&lt;" "&lt;&lt;Xi_size.width&lt;&lt;std::endl;
  
              cv::Mat temp(960,1, CV_8UC1); 
          cv::Mat temp = random_Xi_Vectors[i] * R;
          shares.push_back(temp);
      }
  </code></pre>
  
  <p>And this is the error I am getting: </p>
  
  <pre><code>r@r-HP-Mini-110:~/l33t/Secret Sharing$ ./mainProgram  Sizes of matrices to be multiplied: 
  R : 960 2
  Xi : 2 1
  OpenCV Error: Assertion failed (type == B.type() &amp;&amp; (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in gemm, file /build/buildd/opencv-2.3.1/modules/core/src/matmul.cpp, line 701
  terminate called after throwing an instance of 'cv::Exception'
    what():  /build/buildd/opencv-2.3.1/modules/core/src/matmul.cpp:701: error: (-215) type == B.type() &amp;&amp; (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function gemm
  
  Aborted (core dumped)
  r@r-HP-Mini-110:~/l33t/Secret Sharing$ 
  </code></pre>
  
  <p>As you can see, the number of columns in the first Mat matches the number of rows in the second Mat. Also, the type of both the Mat is the same i.e <code>CV_8UC1</code>. So then why am I getting this error. Please help.</p>