Issue 1:
System information (version)

OpenCV => :4.0beta:

Operating System / Platform => :Windows 64 bit:

Compiler => :Visual studio 2017:

Detailed description

Net is loaded from Onnx, the net just can not successfully update input data from setInput

invalid when call function setInput for the second blob(blob_2):

The result is 1.0 which means set two different input from blob_1 and blob_2 but got the same vector.

The details of code is as follows.

Steps to reproduce

#include <opencv2/opencv.hpp>

#include <opencv2/dnn.hpp>

#include

#include

using namespace std;

using namespace cv;

using namespace cv::dnn;

int test_onnx()

{

Net net_1 = readNetFromONNX(model_path);

if (net_1.empty() || net_2.empty())
{
printf("=> 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 <= 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=> similarity: %.5f\n", sim);

return 0;}

Issue 2:
System information (version)

OpenCV => 4eb2966

Operating System / Platform => Windows 64 Bit

Compiler => Visual Studio 2017

Detailed description

When compiling with MKL and OpenMP, parallel.cpp defines ProxyLoopBody in such a way that it is missing an overload that accepts cv::Range, yet is called elsewhere with a cv::Range argument.

Steps to reproduce

Current version:

#elif defined WINRT || defined HAVE_CONCURRENCY
class ProxyLoopBody : public ParallelLoopBodyWrapper
{
public:
ProxyLoopBody(ParallelLoopBodyWrapperContext& ctx)
: ParallelLoopBodyWrapper(ctx)
{}

void operator ()(int i) const
{
this->ParallelLoopBodyWrapper::operator()(cv::Range(i, i + 1));
}
};
#else
typedef ParallelLoopBodyWrapper ProxyLoopBody;
#endif

Fix:

#elif defined WINRT || defined HAVE_CONCURRENCY
class ProxyLoopBody : public ParallelLoopBodyWrapper
{
public:
ProxyLoopBody(ParallelLoopBodyWrapperContext& ctx)
: ParallelLoopBodyWrapper(ctx)
{}

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

void operator ()(const cv::Range& range) const
{
this->ParallelLoopBodyWrapper::operator()(range);
}
};
#else
typedef ParallelLoopBodyWrapper ProxyLoopBody;
#endif