title: Have exception in OpenCV when converting an image to grayscale
body: <p>Have strange error.<br> I try to convert Image to grayscale and,after that print result matrix to file, but get exception: </p>
  
  <blockquote>
    <p>"Unhandled exception at 0x00007FF965E31F28 in ConsoleApplication1.exe:
    Microsoft C++ exception: cv::Exception at memory location
    0x00000041305AF2A0.</p>
  </blockquote>
  
  <p>Following code is below.<br> Can somebody say me when I made mistake?</p>
  
  <pre><code>int main()
  {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      string fname;
      cin &gt;&gt; fname;
  
      cv::Mat img = readImage(fname);
  
      cv::Mat grayImg(img.size(), CV_64FC1);
      if (img.channels() == 3)
      {
          cvtColor(img, grayImg, CV_BGR2GRAY);
      }
      else
      {
          img.copyTo(grayImg);
      }
      printImg(grayImg);
  
      cv::waitKey();
      return 0;
  }
  void printImg(cv::Mat &amp;img)
  {
      cout &lt;&lt; "---------//------\n";
      if (img.empty())
      {
          cout &lt;&lt; "Empty Image\n";
          return;
      }
  
      for (int i = 0; i &lt; img.size().height; i++)
      {
          for (int j = 0; j &lt; img.size().width; j++)
          {
              cout &lt;&lt; img.at&lt;double&gt;(i, j) &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
      cout &lt;&lt; "---------//------\n";
  }
  </code></pre>
  
  <p>error in string <br></p>
  
  <pre><code>cout &lt;&lt; img.at&lt;double&gt;(i, j) &lt;&lt; " ";
  </code></pre>