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

<ul dir="auto">
<li>OpenCV =&gt; :4.0beta:</li>
<li>Operating System / Platform =&gt; :Windows 64 bit:</li>
<li>Compiler =&gt; :Visual studio 2017:</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Net is loaded from Onnx, the net just can not successfully update input data from setInput<br>
invalid when call function setInput for the second blob(blob_2):<br>
The result is 1.0 which means set two different input from blob_1 and blob_2 but got the same vector.<br>
The details of code is as follows.</p>

<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">#include &lt;opencv2/opencv.hpp&gt;<br>
#include &lt;opencv2/dnn.hpp&gt;<br>
#include <br>
#include </p>
<p dir="auto">using namespace std;<br>
using namespace cv;<br>
using namespace cv::dnn;</p>
<p dir="auto">int test_onnx()<br>
{</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Net net_1 = readNetFromONNX(model_path);

if (net_1.empty() || net_2.empty())
{
    printf(&quot;=&gt; net load failed.\n&quot;);
    return -1;
}
const String img_1_path = &quot;../img_1.jpg&quot;;
const String img_2_path = &quot;../img_3.jpg&quot;;
Mat img_1, img_2;
img_1 = imread(img_1_path, IMREAD_GRAYSCALE);
img_2 = imread(img_2_path, IMREAD_GRAYSCALE);

if (img_1.empty() || img_2.empty())
{
    printf(&quot;[Err]: empty dir.\n&quot;);
    return -1;
}
img_1.convertTo(img_1, CV_32F);
img_2.convertTo(img_2, CV_32F);

// padding
int H = img_1.rows;
int W = img_1.cols;
int dim_diff = std::abs(H - W);
int top, bottom, left, right;
if (H &lt;= W)
{
    top = dim_diff / 2;
    bottom = dim_diff - top;
    left = 0;
    right = 0;
}
else
{
    left = dim_diff / 2;
    right = dim_diff - left;
    top = 0;
    bottom = 0;
}

Mat img_1_pad, img_2_pad;
copyMakeBorder(img_1, img_1_pad,
    top, bottom, left, right, BORDER_CONSTANT, 127.5);
copyMakeBorder(img_2, img_2_pad,
    top, bottom, left, right, BORDER_CONSTANT, 127.5);

// construct blob
Mat blob_1, blob_2;
blob_1 = blobFromImage(
    img_1_pad,
    1.0 / 127.5f,
    Size(224, 224), 
    127.5,
    true);
blob_2 = blobFromImage(
    img_2_pad,
    1.0 / 127.5f,
    Size(224, 224),
    127.5,
    true);

// inference: get features
net_1.setInput(blob_1);
Mat feature_1 = net_1.forward();
net_1.setInput(blob_2);  // invalid here...
Mat feature_2 = net_1.forward();

// vector dot
double dot = feature_1.dot(feature_2);

// L2 norm
double feature_1_norm = norm(feature_1, NORM_L2);
double feature_2_norm = norm(feature_2, NORM_L2);

// cosine similarity
double sim = dot / (feature_1_norm * feature_2_norm);
printf(&quot;\n=&gt; similarity: %.5f\n&quot;, sim);

return 0;}"><pre class="notranslate"><code class="notranslate">Net net_1 = readNetFromONNX(model_path);

if (net_1.empty() || net_2.empty())
{
    printf("=&gt; net load failed.\n");
    return -1;
}
const String img_1_path = "../img_1.jpg";
const String img_2_path = "../img_3.jpg";
Mat img_1, img_2;
img_1 = imread(img_1_path, IMREAD_GRAYSCALE);
img_2 = imread(img_2_path, IMREAD_GRAYSCALE);

if (img_1.empty() || img_2.empty())
{
    printf("[Err]: empty dir.\n");
    return -1;
}
img_1.convertTo(img_1, CV_32F);
img_2.convertTo(img_2, CV_32F);

// padding
int H = img_1.rows;
int W = img_1.cols;
int dim_diff = std::abs(H - W);
int top, bottom, left, right;
if (H &lt;= W)
{
    top = dim_diff / 2;
    bottom = dim_diff - top;
    left = 0;
    right = 0;
}
else
{
    left = dim_diff / 2;
    right = dim_diff - left;
    top = 0;
    bottom = 0;
}

Mat img_1_pad, img_2_pad;
copyMakeBorder(img_1, img_1_pad,
    top, bottom, left, right, BORDER_CONSTANT, 127.5);
copyMakeBorder(img_2, img_2_pad,
    top, bottom, left, right, BORDER_CONSTANT, 127.5);

// construct blob
Mat blob_1, blob_2;
blob_1 = blobFromImage(
    img_1_pad,
    1.0 / 127.5f,
    Size(224, 224), 
    127.5,
    true);
blob_2 = blobFromImage(
    img_2_pad,
    1.0 / 127.5f,
    Size(224, 224),
    127.5,
    true);

// inference: get features
net_1.setInput(blob_1);
Mat feature_1 = net_1.forward();
net_1.setInput(blob_2);  // invalid here...
Mat feature_2 = net_1.forward();

// vector dot
double dot = feature_1.dot(feature_2);

// L2 norm
double feature_1_norm = norm(feature_1, NORM_L2);
double feature_2_norm = norm(feature_2, NORM_L2);

// cosine similarity
double sim = dot / (feature_1_norm * feature_2_norm);
printf("\n=&gt; similarity: %.5f\n", sim);

return 0;}
</code></pre></div>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/opencv/opencv/commit/4eb296655958e9241f43a7bd144d5e63759f6cea/hovercard" href="https://github.com/opencv/opencv/commit/4eb296655958e9241f43a7bd144d5e63759f6cea"><tt>4eb2966</tt></a></li>
<li>Operating System / Platform =&gt; Windows 64 Bit</li>
<li>Compiler =&gt; Visual Studio 2017</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">When compiling with MKL and OpenMP, <code class="notranslate">parallel.cpp</code> defines <code class="notranslate">ProxyLoopBody</code> in such a way that it is missing an overload that accepts <code class="notranslate">cv::Range</code>, yet is called elsewhere with a <code class="notranslate">cv::Range</code> argument.</p>
<h5 dir="auto">Steps to reproduce</h5>

<p dir="auto">Current version:</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#elif defined WINRT || defined HAVE_CONCURRENCY
    class ProxyLoopBody : public ParallelLoopBodyWrapper
    {
    public:
        ProxyLoopBody(ParallelLoopBodyWrapperContext&amp; ctx)
        : ParallelLoopBodyWrapper(ctx)
        {}

        void operator ()(int i) const
        {
            this-&gt;ParallelLoopBodyWrapper::operator()(cv::Range(i, i + 1));
        }
    };
#else
    typedef ParallelLoopBodyWrapper ProxyLoopBody;
#endif"><pre class="notranslate">#<span class="pl-k">elif</span> defined WINRT || defined HAVE_CONCURRENCY
    <span class="pl-k">class</span> <span class="pl-en">ProxyLoopBody</span> : <span class="pl-k">public</span> <span class="pl-en">ParallelLoopBodyWrapper</span>
    {
    <span class="pl-k">public:</span>
        <span class="pl-en">ProxyLoopBody</span>(ParallelLoopBodyWrapperContext&amp; ctx)
        : ParallelLoopBodyWrapper(ctx)
        {}

        <span class="pl-k">void</span> <span class="pl-en">operator</span> ()(<span class="pl-k">int</span> i) <span class="pl-k">const</span>
        {
            <span class="pl-c1">this</span>-&gt;<span class="pl-smi">ParallelLoopBodyWrapper</span><span class="pl-c1">::operator</span>()(<span class="pl-c1">cv::Range</span>(i, i + <span class="pl-c1">1</span>));
        }
    };
#<span class="pl-k">else</span>
    <span class="pl-k">typedef</span> ParallelLoopBodyWrapper ProxyLoopBody;
#endif</pre></div>
<p dir="auto">Fix:</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#elif defined WINRT || defined HAVE_CONCURRENCY
    class ProxyLoopBody : public ParallelLoopBodyWrapper
    {
    public:
        ProxyLoopBody(ParallelLoopBodyWrapperContext&amp; ctx)
        : ParallelLoopBodyWrapper(ctx)
        {}

        void operator ()(int i) const
        {
            this-&gt;ParallelLoopBodyWrapper::operator()(cv::Range(i, i + 1));
        }

	void operator ()(const cv::Range&amp; range) const
	{
		this-&gt;ParallelLoopBodyWrapper::operator()(range);
	}
    };
#else
    typedef ParallelLoopBodyWrapper ProxyLoopBody;
#endif"><pre class="notranslate">#<span class="pl-k">elif</span> defined WINRT || defined HAVE_CONCURRENCY
    <span class="pl-k">class</span> <span class="pl-en">ProxyLoopBody</span> : <span class="pl-k">public</span> <span class="pl-en">ParallelLoopBodyWrapper</span>
    {
    <span class="pl-k">public:</span>
        <span class="pl-en">ProxyLoopBody</span>(ParallelLoopBodyWrapperContext&amp; ctx)
        : ParallelLoopBodyWrapper(ctx)
        {}

        <span class="pl-k">void</span> <span class="pl-en">operator</span> ()(<span class="pl-k">int</span> i) <span class="pl-k">const</span>
        {
            <span class="pl-c1">this</span>-&gt;<span class="pl-smi">ParallelLoopBodyWrapper</span><span class="pl-c1">::operator</span>()(<span class="pl-c1">cv::Range</span>(i, i + <span class="pl-c1">1</span>));
        }

	<span class="pl-k">void</span> <span class="pl-en">operator</span> ()(<span class="pl-k">const</span> cv::Range&amp; range) <span class="pl-k">const</span>
	{
		<span class="pl-c1">this</span>-&gt;<span class="pl-smi">ParallelLoopBodyWrapper</span><span class="pl-c1">::operator</span>()(range);
	}
    };
#<span class="pl-k">else</span>
    <span class="pl-k">typedef</span> ParallelLoopBodyWrapper ProxyLoopBody;
#endif</pre></div>