title: Converting OpenCV grayscale Mat to Caffe blob
body: <p>I've been <a href="https://github.com/jyegerlehner/caffe/blob/nat_img_autoenc_parallel/tools/prop-patches.cpp" rel="nofollow">following an example</a> I was referred to on how to convert an OpenCV <code>Mat</code> into a Caffe object I could make predictions from. From what I understand, the first section scales the image and then initialises the caffe class <code>TransformationParameter</code>:</p>
  
  <pre><code>const float img_to_net_scale = 0.0039215684;
  TransformationParameter input_xform_param;
  input_xform_param.set_scale( img_to_net_scale );
  DataTransformer&lt;float&gt; input_xformer( input_xform_param, TEST );
  </code></pre>
  
  <p>Then, the OpenCV Mat "patch" is converted into "input_blob". I've changed this part because I've loaded in my image in grayscale instead of colour. </p>
  
  <pre><code>cv::Mat patch = cv::imread( input_file_str, CV_LOAD_IMAG_GRAYSCALE  );
  Blob&lt;float&gt; input_blob;
  input_blob.Reshape(1, patch.channels(), patch.rows, patch.cols );
  input_xformer.Transform( patch, &amp;input_blob );
  </code></pre>
  
  <p>Finally, I'm not too sure what this section does - if I already have my OpenCV Mat converted to a Caffe blob, why do I need to push back on the "input" vector and pass it to the net? Can't I pass input_blob directly into the net to get my prediction back?</p>
  
  <pre><code>std::vector&lt;Blob&lt;float&gt;*&gt; input;
  input.push_back( &amp;input_blob );
  
  std::vector&lt;Blob&lt;float&gt;*&gt; output = net-&gt;Forward( input );
  </code></pre>