title: Loading an image from a URL into a variable/opencv Mat
body: <pre><code>bool loadImage(string inputName, Mat &amp;image)
  {
    bool from_net = true;
  
    if (inputName.find("http") != string::npos)
      {
        string URL = inputName;
        if (inputName.find("\"") == 0)
          {
            URL = inputName.substr(1,inputName.length()-2);
          }
        ofstream myfile;
        myfile.open ("test.jpg");
        //  Create a writer to handle the stream
  
        curl_writer writer(myfile);
        // Pass it to the easy constructor and watch the content returned in that file!
        curl_easy easy(writer);
  
        // Add some option to the easy handle
        easy.add(curl_pair&lt;CURLoption,string&gt;(CURLOPT_URL,URL));
        easy.add(curl_pair&lt;CURLoption,long&gt;(CURLOPT_FOLLOWLOCATION,1L));
        try {
          easy.perform();
        } catch (curl_easy_exception error) {
          // If you want to get the entire error stack we can do:
          vector&lt;pair&lt;string,string&gt;&gt; errors = error.what();
          // Otherwise we could print the stack like this:
          //error.print_traceback();
        }
        myfile.close();
  
        string inputname = "test.jpg";
        image = imread(inputname,1);
  
        if(image.rows == 0 || image.cols == 0)
            from_net = false;
      }  
    else
      {
        image = imread( inputName, 1 );
        if (image.total() &lt; 1)         
            from_net = false;
  
      }
    return from_net; 
  }
  </code></pre>
  
  <p>And this works fine for my application, if I change <code>test.txt</code> to <code>test.jpg</code>. However, my application demands that I avoid the overhead of creating the file, reading, writing and closing it. Is there an easy and direct way to get the image data from the URL and write it to an openCV Mat ?</p>
  
  <p>I also tried the 3rd example in the above link. But for some reason when I do a <code>receiver.get_buffer()</code>, the image remains empty. I get image dimensions as <code>0X0</code>. </p>
  
  <p>Any help related to this is really appreciated. I have never used curlcpp before and so, any detailed explanation for the same would be much appreciated.</p>
  
  <p>Thanks.</p>