title: OpenCV: Replace ilLoadImage with cv::imread
body: <p>I'm using <a href="https://github.com/sloup/hessgpu" rel="nofollow noreferrer"><code>hessgpu</code></a> for efficiently compute hessian-affine SIFT descriptors using GPUs.</p>
  
  <p>In this project, <a href="http://openil.sourceforge.net/" rel="nofollow noreferrer">Devil</a> is used for reading images: if <code>SiftGPU::RunSIFT(const char *imgpath)</code> is called (implemented <a href="https://github.com/sloup/hessgpu/blob/master/src/SiftGPU/SiftGPU.cpp" rel="nofollow noreferrer">here</a>), then <a href="https://www.google.it/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwjT5qCXovvSAhWIzxQKHUJ3BdkQFggcMAA&amp;url=http%3A%2F%2Fwww-f9.ijs.si%2F~matevz%2Fdocs%2FDevIL%2Fil%2Ff00039.htm&amp;usg=AFQjCNFA86lmJX1CqzThnbEtvON2Yj69zg&amp;sig2=UZevokqELZh7hBmEV5Pj8g" rel="nofollow noreferrer"><code>ilLoadImage</code></a> is used in <a href="https://github.com/sloup/hessgpu/blob/master/src/SiftGPU/GLTexImage.cpp" rel="nofollow noreferrer">GLTexImage.cpp</a> for reading images (as RGB images).</p>
  
  <p>However, in my project I use <a href="http://docs.opencv.org/3.1.0/d4/da8/group__imgcodecs.html" rel="nofollow noreferrer"><code>cv::imread</code></a> to read images. The project provides <code>SiftGPU::RunSIFT(int width, int height, const void * data, unsigned int gl_format, unsigned int gl_type)</code> to compute descriptors from data provided directly from the user.</p>
  
  <p>So I tried:</p>
  
  <pre><code>cv::Mat img = cv::imread("image.jpg", cv::IMREAD_GRAYSCALE);
  sift.RunSIFT(img.cols, img.rows, img.data, GL_LUMINANCE, GL_UNSIGNED_BYTE);
  </code></pre>
  
  <p>But this produce slightly less keypoints than <code>sift.RunSIFT("image.jpg");</code>. I tried to use:</p>
  
  <pre><code>cv::Mat img = cv::imread("image.jpg");
  sift.RunSIFT(img.cols, img.rows, img.data, GL_RGB, GL_UNSIGNED_BYTE);
  </code></pre>
  
  <p>But this produces 0 keypoints, so something very wrong happens. I think:</p>
  
  <ol>
  <li><code>iLoadImage</code> uses RGB image, while the only working method that I found up to now using <code>cv::imread</code> works only with grayscale images.</li>
  <li>It's possible that devil use a different process to read images than OpenCV, espcecially for RGB images (since using the second approach produced 0 keypoints).</li>
  </ol>
  
  <p>How can I do the equivalent of <code>ilLoadimage</code> using <code>cv::imread</code>?   </p>