Skip to content

Commit e85b41f

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents f54f662 + 573812d commit e85b41f

File tree

9 files changed

+413
-183
lines changed

9 files changed

+413
-183
lines changed

modules/core/include/opencv2/core/bindings_utils.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ String testOverloadResolution(const Rect& rect)
7878
rect.width, rect.height);
7979
}
8080

81+
CV_WRAP static inline
82+
String dumpRect(const Rect& argument)
83+
{
84+
return format("rect: (x=%d, y=%d, w=%d, h=%d)", argument.x, argument.y,
85+
argument.width, argument.height);
86+
}
87+
88+
CV_WRAP static inline
89+
String dumpTermCriteria(const TermCriteria& argument)
90+
{
91+
return format("term_criteria: (type=%d, max_count=%d, epsilon=%lf",
92+
argument.type, argument.maxCount, argument.epsilon);
93+
}
94+
95+
CV_WRAP static inline
96+
String dumpRotatedRect(const RotatedRect& argument)
97+
{
98+
return format("rotated_rect: (c_x=%f, c_y=%f, w=%f, h=%f, a=%f)",
99+
argument.center.x, argument.center.y, argument.size.width,
100+
argument.size.height, argument.angle);
101+
}
102+
103+
CV_WRAP static inline
104+
String dumpRange(const Range& argument)
105+
{
106+
if (argument == Range::all())
107+
{
108+
return "range: all";
109+
}
110+
else
111+
{
112+
return format("range: (s=%d, e=%d)", argument.start, argument.end);
113+
}
114+
}
115+
81116
CV_WRAP static inline
82117
AsyncArray testAsyncArray(InputArray argument)
83118
{

modules/core/src/ocl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,14 +1149,14 @@ void OpenCLExecutionContext::release()
11491149
}
11501150

11511151

1152+
11521153
// true if we have initialized OpenCL subsystem with available platforms
1153-
static bool g_isOpenCLActivated = false;
1154+
static bool g_isOpenCLInitialized = false;
1155+
static bool g_isOpenCLAvailable = false;
11541156

11551157
bool haveOpenCL()
11561158
{
11571159
CV_TRACE_FUNCTION();
1158-
static bool g_isOpenCLInitialized = false;
1159-
static bool g_isOpenCLAvailable = false;
11601160

11611161
if (!g_isOpenCLInitialized)
11621162
{
@@ -1178,7 +1178,7 @@ bool haveOpenCL()
11781178
{
11791179
cl_uint n = 0;
11801180
g_isOpenCLAvailable = ::clGetPlatformIDs(0, NULL, &n) == CL_SUCCESS;
1181-
g_isOpenCLActivated = n > 0;
1181+
g_isOpenCLAvailable &= n > 0;
11821182
CV_LOG_INFO(NULL, "OpenCL: found " << n << " platforms");
11831183
}
11841184
catch (...)
@@ -1214,7 +1214,7 @@ bool useOpenCL()
12141214

12151215
bool isOpenCLActivated()
12161216
{
1217-
if (!g_isOpenCLActivated)
1217+
if (!g_isOpenCLAvailable)
12181218
return false; // prevent unnecessary OpenCL activation via useOpenCL()->haveOpenCL() calls
12191219
return useOpenCL();
12201220
}

modules/dnn/misc/python/test/test_dnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_model(self):
177177
cv.rectangle(frame, box, (0, 255, 0))
178178
cv.rectangle(frame, np.array(box), (0, 255, 0))
179179
cv.rectangle(frame, tuple(box), (0, 255, 0))
180-
# FIXIT never properly work: cv.rectangle(frame, list(box), (0, 255, 0))
180+
cv.rectangle(frame, list(box), (0, 255, 0))
181181

182182

183183
def test_classification_model(self):

modules/dnn/src/onnx/onnx_importer.cpp

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,53 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
11621162
layerParams.type = "Scale";
11631163
}
11641164
}
1165+
else if (!haveVariables)
1166+
{
1167+
Mat inp0 = getBlob(node_proto, 0);
1168+
Mat inp1 = getBlob(node_proto, 1);
1169+
1170+
if (inp0.size != inp1.size && (inp0.total() != 1 || inp1.total() != 1))
1171+
CV_Error_(Error::StsNotImplemented, ("Different shapes case is not supported with constant inputs: %s", layer_type.c_str()));
1172+
1173+
if (inp0.total() == 1 && inp1.total() == 1 && inp0.dims != inp1.dims)
1174+
{
1175+
if (inp0.dims < inp1.dims)
1176+
{
1177+
inp0 = inp0.reshape(1, inp1.dims, inp1.size);
1178+
inp0.dims = inp1.dims;
1179+
}
1180+
else
1181+
{
1182+
inp1 = inp1.reshape(1, inp0.dims, inp0.size);
1183+
inp1.dims = inp0.dims;
1184+
}
1185+
}
1186+
1187+
Mat out;
1188+
if (inp0.total() != inp1.total())
1189+
{
1190+
if (inp0.total() == 1)
1191+
{
1192+
float coeff = isDiv ? 1.0 / inp0.at<float>(0) : inp0.at<float>(0);
1193+
multiply(inp1, coeff, out);
1194+
}
1195+
else
1196+
{
1197+
float coeff = isDiv ? 1.0 / inp1.at<float>(0) : inp1.at<float>(0);
1198+
multiply(inp0, coeff, out);
1199+
}
1200+
1201+
}
1202+
else
1203+
{
1204+
out = isDiv ? inp0 / inp1 : inp0.mul(inp1);
1205+
}
1206+
1207+
if (inp0.dims == 1 && inp1.dims == 1)
1208+
out.dims = 1; // to workaround dims == 1
1209+
addConstant(layerParams.name, out);
1210+
return;
1211+
}
11651212
else if (outShapes[node_proto.input(0)] == outShapes[node_proto.input(1)])
11661213
{
11671214
layerParams.type = "Eltwise";
@@ -1201,20 +1248,6 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
12011248
}
12021249
layerParams.type = "Scale";
12031250
}
1204-
1205-
if (!haveVariables)
1206-
{
1207-
Mat inp0 = getBlob(node_proto, 0);
1208-
Mat inp1 = getBlob(node_proto, 1);
1209-
if (inp0.size != inp1.size && inp1.total() != 1)
1210-
CV_Error(Error::StsNotImplemented, "Constant multiply with different shapes");
1211-
1212-
Mat out = isDiv ? inp0 / inp1 : inp0.mul(inp1);
1213-
out = out.reshape(1, inp0.dims, inp0.size);
1214-
out.dims = inp0.dims; // to workaround dims == 1
1215-
addConstant(layerParams.name, out);
1216-
return;
1217-
}
12181251
}
12191252
else if (layer_type == "Conv")
12201253
{
@@ -1733,9 +1766,26 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto_)
17331766
if (!hasVariableInps)
17341767
{
17351768
std::vector<Mat> inputs(node_proto.input_size()), concatenated;
1769+
// Due constant folding we can get inputs with different number of dimensions
1770+
// Insert the missing dimension to inputs
1771+
MatShape inputShape;
17361772
for (size_t i = 0; i < inputs.size(); ++i)
17371773
{
17381774
inputs[i] = getBlob(node_proto, i);
1775+
if (inputs[i].size.dims() > inputShape.size())
1776+
{
1777+
inputShape = shape(inputs[i]);
1778+
}
1779+
}
1780+
1781+
// Concat-1 has default value for axis is 1: https://github.com/onnx/onnx/blob/master/docs/Changelog.md#Concat-1
1782+
int axis = layerParams.get<int>("axis", 1);
1783+
for (size_t i = 0; i < inputs.size(); ++i)
1784+
{
1785+
MatShape targetShape = inputShape;
1786+
targetShape[axis] = shape(inputs[i])[axis];
1787+
CV_CheckEQ(total(targetShape), total(shape(inputs[i])), "");
1788+
inputs[i] = inputs[i].reshape(0, targetShape);
17391789
}
17401790
runLayer(layerParams, inputs, concatenated);
17411791

modules/dnn/src/tensorflow/tf_importer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,18 @@ void TFImporter::parseNode(const tensorflow::NodeDef& layer_)
12281228

12291229
int kernel_blob_index = -1;
12301230
const tensorflow::TensorProto& kernelTensor = getConstBlob(layer, value_id, -1, &kernel_blob_index);
1231-
blobFromTensor(kernelTensor, layerParams.blobs[0]);
1232-
releaseTensor(const_cast<tensorflow::TensorProto*>(&kernelTensor));
1231+
const String kernelTensorName = layer.input(kernel_blob_index);
1232+
std::map<String, Mat>::iterator sharedWeightsIt = sharedWeights.find(kernelTensorName);
1233+
if (sharedWeightsIt == sharedWeights.end())
1234+
{
1235+
blobFromTensor(kernelTensor, layerParams.blobs[0]);
1236+
releaseTensor(const_cast<tensorflow::TensorProto*>(&kernelTensor));
1237+
sharedWeights[kernelTensorName] = layerParams.blobs[0];
1238+
}
1239+
else
1240+
{
1241+
layerParams.blobs[0] = sharedWeightsIt->second;
1242+
}
12331243

12341244
if (kernel_blob_index == 1) { // In this case output is computed by x*W formula - W should be transposed
12351245
Mat data = layerParams.blobs[0].t();

modules/dnn/test/test_onnx_importer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,11 @@ TEST_P(Test_ONNX_layers, Mish)
706706
testONNXModels("mish");
707707
}
708708

709+
TEST_P(Test_ONNX_layers, CalculatePads)
710+
{
711+
testONNXModels("calc_pads");
712+
}
713+
709714
TEST_P(Test_ONNX_layers, Conv1d)
710715
{
711716
testONNXModels("conv1d");

modules/highgui/src/window_w32.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,26 +1118,20 @@ static void icvScreenToClient( HWND hwnd, RECT* rect )
11181118
/* Calculatess the window coordinates relative to the upper left corner of the mainhWnd window */
11191119
static RECT icvCalcWindowRect( CvWindow* window )
11201120
{
1121-
const int gutter = 1;
1122-
RECT crect = { 0 }, trect = { 0 } , rect = { 0 };
1121+
RECT crect = { 0 }, trect = { 0 }, rect = { 0 };
11231122

11241123
assert(window);
11251124

11261125
GetClientRect(window->frame, &crect);
1127-
if(window->toolbar.toolbar)
1126+
if (window->toolbar.toolbar)
11281127
{
11291128
GetWindowRect(window->toolbar.toolbar, &trect);
11301129
icvScreenToClient(window->frame, &trect);
1131-
SubtractRect( &rect, &crect, &trect);
1130+
SubtractRect(&rect, &crect, &trect);
11321131
}
11331132
else
11341133
rect = crect;
11351134

1136-
rect.top += gutter;
1137-
rect.left += gutter;
1138-
rect.bottom -= gutter;
1139-
rect.right -= gutter;
1140-
11411135
return rect;
11421136
}
11431137

0 commit comments

Comments
 (0)