<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; :3.4.9</li>
<li>Operating System / Platform =&gt; Ubuntu 16.04</li>
<li>Compiler =&gt; :gcc 5.4.0 20160609</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">Is there any way to call imread() without filename but with image array?</p>
<h5 dir="auto">Steps to reproduce</h5>

<p dir="auto">This is not a bug. But I want to know how to load image without filename.<br>
If I have received an image from somewhere and I want to load it as Opencv matrix,<br>
I think it will be better to convert without writing file.<br>
But now I have to write the image to file and call imread() function.<br>
If there is another way to read image without writing file, please let me know.</p>
<p dir="auto">Thank you.</p>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 3.4.6</li>
<li>Operating System / Platform =&gt; Windows 10 64 Bit</li>
<li>Compiler =&gt; Visual Studio 2017</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Using OpenCV functions <code class="notranslate">cv::absdiff</code>, <code class="notranslate">cv::sum</code>, and <code class="notranslate">cv::minMaxIdx</code> one can calculate that the <em>sum</em> of the absolute difference of 2 matrices is less than the greatest single absolute difference of a single element.</p>
<p dir="auto">sum |A-B| &lt; max |A-B|</p>
<p dir="auto">To my knowledge this only occurs after calling <code class="notranslate">convertTo()</code> on a <code class="notranslate">Mat</code> with more than 2 dimensions.<br>
In other words:</p>
<ul dir="auto">
<li>using 2D <code class="notranslate">Mat</code>s is not a problem, <em>and</em></li>
<li>using 3D <code class="notranslate">Mat</code>s <em>without</em> calling <code class="notranslate">converTo()</code> is not a problem,<br>
<strong>BUT</strong></li>
<li>using 3D <code class="notranslate">Mat</code>s and calling <code class="notranslate">convertTo()</code> will result in what should be an impossible result.</li>
</ul>
<h5 dir="auto">Minimal Example To Reproduce</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;iostream&gt;

#include &lt;opencv/cv.h&gt;

//*****************************************************************************
//*****************************************************************************
bool CalculateSumOfErrorAndMaxError(
  const cv::Mat&amp; A,
  const cv::Mat&amp; B)
{
  cv::Mat AbsDiff;
  double SumAbsDiff;
  double MaxAbsDiff;

  cv::absdiff(A, B, AbsDiff);
  SumAbsDiff = cv::sum(AbsDiff)[0];
  cv::minMaxIdx(AbsDiff, NULL, &amp;MaxAbsDiff, NULL, NULL);

  std::cout &lt;&lt; &quot;SumAbsDiff: &quot; &lt;&lt; SumAbsDiff &lt;&lt; std::endl;
  std::cout &lt;&lt; &quot;MaxAbsDiff: &quot; &lt;&lt; MaxAbsDiff &lt;&lt; std::endl;

  bool ImpossibleResult = SumAbsDiff &lt; MaxAbsDiff;

  return ImpossibleResult;
}

//*****************************************************************************
//*****************************************************************************
int main()
{
  const int Size[] = { 10, 10, 10 };
  cv::Mat A(3, Size, CV_64F);
  cv::randu(A, 0.0, 3.0);

  cv::Mat B = A.clone();

  A.convertTo(A, CV_32F);
  B.convertTo(B, CV_32F);

  CalculateSumOfErrorAndMaxError(A, B);

  return 0;
}"><pre class="notranslate"><code class="notranslate">#include &lt;iostream&gt;

#include &lt;opencv/cv.h&gt;

//*****************************************************************************
//*****************************************************************************
bool CalculateSumOfErrorAndMaxError(
  const cv::Mat&amp; A,
  const cv::Mat&amp; B)
{
  cv::Mat AbsDiff;
  double SumAbsDiff;
  double MaxAbsDiff;

  cv::absdiff(A, B, AbsDiff);
  SumAbsDiff = cv::sum(AbsDiff)[0];
  cv::minMaxIdx(AbsDiff, NULL, &amp;MaxAbsDiff, NULL, NULL);

  std::cout &lt;&lt; "SumAbsDiff: " &lt;&lt; SumAbsDiff &lt;&lt; std::endl;
  std::cout &lt;&lt; "MaxAbsDiff: " &lt;&lt; MaxAbsDiff &lt;&lt; std::endl;

  bool ImpossibleResult = SumAbsDiff &lt; MaxAbsDiff;

  return ImpossibleResult;
}

//*****************************************************************************
//*****************************************************************************
int main()
{
  const int Size[] = { 10, 10, 10 };
  cv::Mat A(3, Size, CV_64F);
  cv::randu(A, 0.0, 3.0);

  cv::Mat B = A.clone();

  A.convertTo(A, CV_32F);
  B.convertTo(B, CV_32F);

  CalculateSumOfErrorAndMaxError(A, B);

  return 0;
}
</code></pre></div>
<p dir="auto">This should produce the output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SumAbsDiff: 0  
MaxAbsDiff: 1  "><pre class="notranslate"><code class="notranslate">SumAbsDiff: 0  
MaxAbsDiff: 1  
</code></pre></div>