From 97681d0607e9fe25b05cd0ae7a3ce7dfeb13c55b Mon Sep 17 00:00:00 2001 From: LaurentBerger Date: Sun, 30 Jun 2019 18:39:05 +0200 Subject: [PATCH 01/23] Add clip to deploy.prototxt --- samples/dnn/face_detector/deploy.prototxt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/dnn/face_detector/deploy.prototxt b/samples/dnn/face_detector/deploy.prototxt index 905580ee46..75d33f00b0 100644 --- a/samples/dnn/face_detector/deploy.prototxt +++ b/samples/dnn/face_detector/deploy.prototxt @@ -1784,6 +1784,7 @@ layer { } code_type: CENTER_SIZE keep_top_k: 200 - confidence_threshold: 0.01 + confidence_threshold: 0.2 + clip: 1 } } From a0c3bb70a9a755e7d57a1f200b8a22e88bf29131 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Fri, 26 Jul 2019 13:57:08 +0300 Subject: [PATCH 02/23] Modify SSD from TensorFlow graph generation script to enable MyriadX --- modules/dnn/perf/perf_net.cpp | 4 ---- modules/dnn/test/test_backends.cpp | 8 -------- modules/dnn/test/test_tf_importer.cpp | 12 +----------- samples/dnn/tf_text_graph_ssd.py | 8 ++++++-- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/modules/dnn/perf/perf_net.cpp b/modules/dnn/perf/perf_net.cpp index cd357bc343..fa4b2f9349 100644 --- a/modules/dnn/perf/perf_net.cpp +++ b/modules/dnn/perf/perf_net.cpp @@ -142,8 +142,6 @@ PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow) { if (backend == DNN_BACKEND_HALIDE) throw SkipTestException(""); - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - throw SkipTestException(""); processNet("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", "ssd_mobilenet_v1_coco_2017_11_17.pbtxt", "", Mat(cv::Size(300, 300), CV_32FC3)); } @@ -152,8 +150,6 @@ PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow) { if (backend == DNN_BACKEND_HALIDE) throw SkipTestException(""); - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - throw SkipTestException(""); processNet("dnn/ssd_mobilenet_v2_coco_2018_03_29.pb", "ssd_mobilenet_v2_coco_2018_03_29.pbtxt", "", Mat(cv::Size(300, 300), CV_32FC3)); } diff --git a/modules/dnn/test/test_backends.cpp b/modules/dnn/test/test_backends.cpp index ff77a0b330..60d8f4a931 100644 --- a/modules/dnn/test/test_backends.cpp +++ b/modules/dnn/test/test_backends.cpp @@ -205,10 +205,6 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow) applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB); if (backend == DNN_BACKEND_HALIDE) applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE); -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2); -#endif Mat sample = imread(findDataFile("dnn/street.png")); Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false); @@ -248,10 +244,6 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow) applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB); if (backend == DNN_BACKEND_HALIDE) applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE); -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2); -#endif Mat sample = imread(findDataFile("dnn/street.png")); Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false); diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index de42bf3b04..3dd0481f57 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -436,11 +436,6 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_SSD) TEST_P(Test_TensorFlow_nets, MobileNet_v1_SSD) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2); -#endif - checkBackend(); std::string proto = findDataFile("dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt"); std::string model = findDataFile("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", false); @@ -456,7 +451,7 @@ TEST_P(Test_TensorFlow_nets, MobileNet_v1_SSD) Mat out = net.forward(); Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/ssd_mobilenet_v1_coco_2017_11_17.detection_out.npy")); - float scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 7e-3 : 1.5e-5; + float scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.011 : 1.5e-5; float iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.012 : 1e-3; float detectionConfThresh = (target == DNN_TARGET_MYRIAD) ? 0.35 : 0.3; @@ -515,11 +510,6 @@ TEST_P(Test_TensorFlow_nets, MobileNet_v1_SSD_PPN) if (backend == DNN_BACKEND_INFERENCE_ENGINE && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16); #endif -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) - if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2); -#endif - checkBackend(); std::string proto = findDataFile("dnn/ssd_mobilenet_v1_ppn_coco.pbtxt"); std::string model = findDataFile("dnn/ssd_mobilenet_v1_ppn_coco.pb", false); diff --git a/samples/dnn/tf_text_graph_ssd.py b/samples/dnn/tf_text_graph_ssd.py index 730e0bbc25..b0a2fe7604 100644 --- a/samples/dnn/tf_text_graph_ssd.py +++ b/samples/dnn/tf_text_graph_ssd.py @@ -312,12 +312,16 @@ def createSSDGraph(modelPath, configPath, outputPath): addConcatNode('PriorBox/concat', priorBoxes, 'concat/axis_flatten') # Sigmoid for classes predictions and DetectionOutput layer + addReshape('ClassPredictor/concat', 'ClassPredictor/concat3d', [0, -1, num_classes + 1], graph_def) + sigmoid = NodeDef() sigmoid.name = 'ClassPredictor/concat/sigmoid' sigmoid.op = 'Sigmoid' - sigmoid.input.append('ClassPredictor/concat') + sigmoid.input.append('ClassPredictor/concat3d') graph_def.node.extend([sigmoid]) + addFlatten(sigmoid.name, sigmoid.name + '/Flatten', graph_def) + detectionOut = NodeDef() detectionOut.name = 'detection_out' detectionOut.op = 'DetectionOutput' @@ -326,7 +330,7 @@ def createSSDGraph(modelPath, configPath, outputPath): detectionOut.input.append('BoxEncodingPredictor/concat') else: detectionOut.input.append('BoxPredictor/concat') - detectionOut.input.append(sigmoid.name) + detectionOut.input.append(sigmoid.name + '/Flatten') detectionOut.input.append('PriorBox/concat') detectionOut.addAttr('num_classes', num_classes + 1) From 77d4e3e8d2b208fe9b845141ab8f1b8a345d77db Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 27 Jul 2019 13:30:15 +0300 Subject: [PATCH 03/23] Fix 2019R2 tests --- modules/dnn/src/layers/elementwise_layers.cpp | 2 +- modules/dnn/test/test_backends.cpp | 2 +- modules/dnn/test/test_caffe_importer.cpp | 4 ++++ modules/dnn/test/test_darknet_importer.cpp | 2 +- modules/dnn/test/test_layers.cpp | 7 ++++++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/dnn/src/layers/elementwise_layers.cpp b/modules/dnn/src/layers/elementwise_layers.cpp index dd250d8c8c..e89c539f68 100644 --- a/modules/dnn/src/layers/elementwise_layers.cpp +++ b/modules/dnn/src/layers/elementwise_layers.cpp @@ -744,7 +744,7 @@ struct AbsValFunctor #ifdef HAVE_INF_ENGINE InferenceEngine::Builder::Layer initInfEngineBuilderAPI() { - return InferenceEngine::Builder::ReLULayer("").setNegativeSlope(-1); + return InferenceEngine::Builder::ReLULayer("").setNegativeSlope(-0.999999f); } #endif // HAVE_INF_ENGINE diff --git a/modules/dnn/test/test_backends.cpp b/modules/dnn/test/test_backends.cpp index 60d8f4a931..57672d80bc 100644 --- a/modules/dnn/test/test_backends.cpp +++ b/modules/dnn/test/test_backends.cpp @@ -387,7 +387,7 @@ TEST_P(DNNTestNetwork, DenseNet_121) float l1 = 0.0, lInf = 0.0; if (target == DNN_TARGET_OPENCL_FP16) { - l1 = 9e-3; lInf = 5e-2; + l1 = 2e-2; lInf = 9e-2; } else if (target == DNN_TARGET_MYRIAD) { diff --git a/modules/dnn/test/test_caffe_importer.cpp b/modules/dnn/test/test_caffe_importer.cpp index 1a79f6a562..22cedbb9d3 100644 --- a/modules/dnn/test/test_caffe_importer.cpp +++ b/modules/dnn/test/test_caffe_importer.cpp @@ -496,7 +496,11 @@ TEST_P(Test_Caffe_nets, DenseNet_121) float l1 = default_l1, lInf = default_lInf; if (target == DNN_TARGET_OPENCL_FP16) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000) + l1 = 0.04; lInf = 0.21; +#else l1 = 0.017; lInf = 0.0795; +#endif } else if (target == DNN_TARGET_MYRIAD) { diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 2263ce20a3..9a575723cd 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -360,7 +360,7 @@ TEST_P(Test_Darknet_nets, YOLOv3) 1, 2, 0.989633f, 0.450719f, 0.463353f, 0.496305f, 0.522258f, // a car 1, 2, 0.997412f, 0.647584f, 0.459939f, 0.821038f, 0.663947f); // a car - double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.0047 : 8e-5; + double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.006 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; std::string config_file = "yolov3.cfg"; diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 02d33b4c36..bed89990e1 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -233,9 +233,14 @@ TEST_P(Test_Caffe_layers, Dropout) TEST_P(Test_Caffe_layers, Concat) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) +#if defined(INF_ENGINE_RELEASE) +#if INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2019020000) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_2019R1, CV_TEST_TAG_DNN_SKIP_IE_2019R1_1); +#elif INF_ENGINE_VER_MAJOR_EQ(2019020000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_2019R2); +#endif #endif testLayerUsingCaffeModels("layer_concat"); testLayerUsingCaffeModels("layer_concat_optim", true, false); From 47c5ee5d9c3ec0b2fca236b6003eef34aaa9ba56 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 27 Jul 2019 15:03:58 +0300 Subject: [PATCH 04/23] Fixes for OpenCV face detection network --- modules/dnn/misc/face_detector_accuracy.py | 9 +++++++-- modules/dnn/misc/quantize_face_detector.py | 4 ++-- modules/dnn/src/layers/detection_output_layer.cpp | 3 ++- samples/dnn/face_detector/deploy.prototxt | 2 +- samples/dnn/face_detector/opencv_face_detector.pbtxt | 10 ++++++++-- samples/dnn/face_detector/test.prototxt | 5 +++-- samples/dnn/face_detector/train.prototxt | 4 ++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/modules/dnn/misc/face_detector_accuracy.py b/modules/dnn/misc/face_detector_accuracy.py index 2f0350e00d..7d10264041 100644 --- a/modules/dnn/misc/face_detector_accuracy.py +++ b/modules/dnn/misc/face_detector_accuracy.py @@ -154,8 +154,13 @@ if args.proto and args.model: top = int(out[0, 0, i, 4] * img.shape[0]) right = int(out[0, 0, i, 5] * img.shape[1]) bottom = int(out[0, 0, i, 6] * img.shape[0]) - addDetection(detections, imageId, left, top, width=right - left + 1, - height=bottom - top + 1, score=confidence) + + x = max(0, min(left, img.shape[1] - 1)) + y = max(0, min(top, img.shape[0] - 1)) + w = max(0, min(right - x + 1, img.shape[1] - x)) + h = max(0, min(bottom - y + 1, img.shape[0] - y)) + + addDetection(detections, imageId, x, y, w, h, score=confidence) elif args.cascade: cascade = cv.CascadeClassifier(args.cascade) diff --git a/modules/dnn/misc/quantize_face_detector.py b/modules/dnn/misc/quantize_face_detector.py index 6dae0266ee..92e307ea3f 100644 --- a/modules/dnn/misc/quantize_face_detector.py +++ b/modules/dnn/misc/quantize_face_detector.py @@ -173,9 +173,9 @@ conv7_2_h = tf.space_to_batch_nd(conv7_1_h, [1, 1], [[1, 1], [1, 1]], name='Pad_ conv7_2_h = conv(conv7_2_h, stride=2, pad='VALID', name='conv7_2_h', activ=tf.nn.relu) conv8_1_h = conv(conv7_2_h, pad='SAME', name='conv8_1_h', activ=tf.nn.relu) -conv8_2_h = conv(conv8_1_h, pad='SAME', name='conv8_2_h', activ=tf.nn.relu) +conv8_2_h = conv(conv8_1_h, pad='VALID', name='conv8_2_h', activ=tf.nn.relu) conv9_1_h = conv(conv8_2_h, 'conv9_1_h', activ=tf.nn.relu) -conv9_2_h = conv(conv9_1_h, pad='SAME', name='conv9_2_h', activ=tf.nn.relu) +conv9_2_h = conv(conv9_1_h, pad='VALID', name='conv9_2_h', activ=tf.nn.relu) conv4_3_norm = l2norm(layer_256_1_relu1, 'conv4_3_norm') diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index fd2bf49794..3515a2b6bb 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -198,7 +198,7 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { return backendId == DNN_BACKEND_OPENCV || - (backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized && !_clip); + (backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized); } bool getMemoryShapes(const std::vector &inputs, @@ -936,6 +936,7 @@ public: InferenceEngine::Builder::Layer l = ieLayer; l.getParameters()["eta"] = std::string("1.0"); + l.getParameters()["clip"] = _clip; return Ptr(new InfEngineBackendNode(l)); } diff --git a/samples/dnn/face_detector/deploy.prototxt b/samples/dnn/face_detector/deploy.prototxt index 75d33f00b0..72e50af434 100644 --- a/samples/dnn/face_detector/deploy.prototxt +++ b/samples/dnn/face_detector/deploy.prototxt @@ -1784,7 +1784,7 @@ layer { } code_type: CENTER_SIZE keep_top_k: 200 - confidence_threshold: 0.2 + confidence_threshold: 0.01 clip: 1 } } diff --git a/samples/dnn/face_detector/opencv_face_detector.pbtxt b/samples/dnn/face_detector/opencv_face_detector.pbtxt index 5f498aad50..60daa5e6be 100644 --- a/samples/dnn/face_detector/opencv_face_detector.pbtxt +++ b/samples/dnn/face_detector/opencv_face_detector.pbtxt @@ -1221,7 +1221,7 @@ node { attr { key: "padding" value { - s: "SAME" + s: "VALID" } } attr { @@ -1311,7 +1311,7 @@ node { attr { key: "padding" value { - s: "SAME" + s: "VALID" } } attr { @@ -2337,6 +2337,12 @@ node { i: 400 } } + attr { + key: "clip" + value { + b: true + } + } } node { name: "reshape_before_softmax" diff --git a/samples/dnn/face_detector/test.prototxt b/samples/dnn/face_detector/test.prototxt index f723f3d113..b441698eb0 100644 --- a/samples/dnn/face_detector/test.prototxt +++ b/samples/dnn/face_detector/test.prototxt @@ -917,7 +917,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -983,7 +983,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -1810,6 +1810,7 @@ layer { code_type: CENTER_SIZE keep_top_k: 200 confidence_threshold: 0.01 + clip: 1 } } layer { diff --git a/samples/dnn/face_detector/train.prototxt b/samples/dnn/face_detector/train.prototxt index feec4000d5..d2b8167ca9 100644 --- a/samples/dnn/face_detector/train.prototxt +++ b/samples/dnn/face_detector/train.prototxt @@ -1086,7 +1086,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -1600,7 +1600,7 @@ layer { } convolution_param { num_output: 16 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { From ebaefbb7456a1d625b1a762819854af38fb4c653 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 27 Jul 2019 23:04:25 +0300 Subject: [PATCH 05/23] Remove VGG16 from ONNX test because there is VGG16_bn --- modules/dnn/test/test_onnx_importer.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index aeceb9ac69..a0e122c68b 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -426,14 +426,6 @@ TEST_P(Test_ONNX_nets, RCNN_ILSVRC13) testONNXModels("rcnn_ilsvrc13", pb, 0.0045); } -TEST_P(Test_ONNX_nets, VGG16) -{ - applyTestTag(CV_TEST_TAG_MEMORY_6GB); // > 2.3Gb - - // output range: [-69; 72], after Softmax [0; 0.96] - testONNXModels("vgg16", pb, default_l1, default_lInf, true); -} - TEST_P(Test_ONNX_nets, VGG16_bn) { applyTestTag(CV_TEST_TAG_MEMORY_6GB); // > 2.3Gb From f9f160404a3a3090e1082f34a28879bdb5ed300f Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 27 Jul 2019 22:10:13 +0300 Subject: [PATCH 06/23] Add support for slice from ONNX with multiple outputs --- modules/dnn/src/onnx/onnx_importer.cpp | 41 ++++++++++++++++++++++--- modules/dnn/test/test_onnx_importer.cpp | 7 +++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index ddea2edda0..51f9affe3b 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -465,6 +465,20 @@ void ONNXImporter::populateNet(Net dstNet) } layerParams.set("begin", DictValue::arrayInt(&begin[0], begin.size())); layerParams.set("end", DictValue::arrayInt(&end[0], end.size())); + } + else if (layer_type == "Split") + { + DictValue splits = layerParams.get("split"); + const int numSplits = splits.size(); + CV_Assert(numSplits > 1); + + std::vector slicePoints(numSplits - 1, splits.get(0)); + for (int i = 1; i < splits.size() - 1; ++i) + { + slicePoints[i] = slicePoints[i - 1] + splits.get(i - 1); + } + layerParams.set("slice_point", DictValue::arrayInt(&slicePoints[0], slicePoints.size())); + layerParams.type = "Slice"; } else if (layer_type == "Add" || layer_type == "Sum") { @@ -486,6 +500,11 @@ void ONNXImporter::populateNet(Net dstNet) layerParams.type = "Eltwise"; } } + else if (layer_type == "Max") + { + layerParams.type = "Eltwise"; + layerParams.set("operation", "max"); + } else if (layer_type == "Sub") { Mat blob = getBlob(node_proto, constBlobs, 1); @@ -741,6 +760,16 @@ void ONNXImporter::populateNet(Net dstNet) { layerParams.type = "Permute"; replaceLayerParam(layerParams, "perm", "order"); + + CV_Assert(node_proto.input_size() == 1); + if (constBlobs.find(node_proto.input(0)) != constBlobs.end()) + { + std::vector inputs(1, getBlob(node_proto, constBlobs, 0)), transposed; + runLayer(layerParams, inputs, transposed); + CV_Assert(transposed.size() == 1); + constBlobs.insert(std::make_pair(layerParams.name, transposed[0])); + continue; + } } else if (layer_type == "Unsqueeze") { @@ -906,8 +935,10 @@ void ONNXImporter::populateNet(Net dstNet) } int id = dstNet.addLayer(layerParams.name, layerParams.type, layerParams); - layer_id.insert(std::make_pair(layerParams.name, LayerInfo(id, 0))); - + for (int i = 0; i < node_proto.output_size(); ++i) + { + layer_id.insert(std::make_pair(node_proto.output(i), LayerInfo(id, i))); + } std::vector layerInpShapes, layerOutShapes, layerInternalShapes; for (int j = 0; j < node_proto.input_size(); j++) { @@ -924,8 +955,10 @@ void ONNXImporter::populateNet(Net dstNet) // Compute shape of output blob for this layer. Ptr layer = dstNet.getLayer(id); layer->getMemoryShapes(layerInpShapes, 0, layerOutShapes, layerInternalShapes); - CV_Assert(!layerOutShapes.empty()); - outShapes[layerParams.name] = layerOutShapes[0]; + for (int i = 0; i < node_proto.output_size() && i < (int)layerOutShapes.size(); ++i) + { + outShapes[node_proto.output(i)] = layerOutShapes[i]; + } } } diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index aeceb9ac69..fa6ee92a20 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -348,6 +348,13 @@ TEST_P(Test_ONNX_layers, Softmax) testONNXModels("log_softmax", npy, 0, 0, false, false); } +TEST_P(Test_ONNX_layers, Split_EltwiseMax) +{ + if (backend == DNN_BACKEND_INFERENCE_ENGINE) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE); + testONNXModels("split_max"); +} + INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets()); class Test_ONNX_nets : public Test_ONNX_layers From 59864a3bbc780b604b2319111004855fac5ba805 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sun, 28 Jul 2019 22:32:37 +0300 Subject: [PATCH 07/23] Fix #14993 --- samples/dnn/tf_text_graph_ssd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/dnn/tf_text_graph_ssd.py b/samples/dnn/tf_text_graph_ssd.py index 730e0bbc25..2cc74fd0dd 100644 --- a/samples/dnn/tf_text_graph_ssd.py +++ b/samples/dnn/tf_text_graph_ssd.py @@ -67,7 +67,7 @@ def createSSDGraph(modelPath, configPath, outputPath): 'Sub', 'ResizeNearestNeighbor', 'Pad'] # Node with which prefixes should be removed - prefixesToRemove = ('MultipleGridAnchorGenerator/', 'Postprocessor/', 'Preprocessor/map') + prefixesToRemove = ('MultipleGridAnchorGenerator/', 'Concatenate/', 'Postprocessor/', 'Preprocessor/map') # Load a config file. config = readTextMessage(configPath) From 4d3989817c9e4e3274723bfe97e49150b134e95b Mon Sep 17 00:00:00 2001 From: berak Date: Mon, 29 Jul 2019 10:49:42 +0200 Subject: [PATCH 08/23] java: fix Mat.toString() for higher dimensions --- modules/core/misc/java/src/java/core+Mat.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/core/misc/java/src/java/core+Mat.java b/modules/core/misc/java/src/java/core+Mat.java index c75f9d5c01..a666e86589 100644 --- a/modules/core/misc/java/src/java/core+Mat.java +++ b/modules/core/misc/java/src/java/core+Mat.java @@ -954,8 +954,11 @@ public class Mat { // javadoc:Mat::toString() @Override public String toString() { - return "Mat [ " + - rows() + "*" + cols() + "*" + CvType.typeToString(type()) + + String _dims = (dims() > 0) ? "" : "-1*-1*"; + for (int i=0; i Date: Tue, 30 Jul 2019 17:23:47 +0300 Subject: [PATCH 09/23] Support for several min and max sizes in PriorBox layer (Merge pull request #15076) * Support for several min and max sizes in PriorBox layer * Fix minSize * Check size * Modify initInfEngine * Fix tests * Fix IE support * Add priorbox test * Remove inputs --- modules/dnn/misc/caffe/opencv-caffe.pb.cc | 207 +++++++++++---------- modules/dnn/misc/caffe/opencv-caffe.pb.h | 174 +++++++++-------- modules/dnn/src/caffe/opencv-caffe.proto | 4 +- modules/dnn/src/layers/prior_box_layer.cpp | 62 +++--- modules/dnn/test/test_layers.cpp | 16 ++ 5 files changed, 255 insertions(+), 208 deletions(-) diff --git a/modules/dnn/misc/caffe/opencv-caffe.pb.cc b/modules/dnn/misc/caffe/opencv-caffe.pb.cc index af84d72279..c46752dc73 100644 --- a/modules/dnn/misc/caffe/opencv-caffe.pb.cc +++ b/modules/dnn/misc/caffe/opencv-caffe.pb.cc @@ -2092,19 +2092,19 @@ const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUT GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::opencv_caffe::PriorBoxParameter, offset_w_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::opencv_caffe::PriorBoxParameter, width_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::opencv_caffe::PriorBoxParameter, height_), - 0, - 1, ~0u, - 8, - 9, ~0u, + ~0u, + 6, + 7, + ~0u, + 0, + 1, 2, 3, 4, 5, - 6, - 7, - 10, + 8, ~0u, ~0u, ~0u, @@ -3528,8 +3528,8 @@ void AddDescriptorsImpl() { "al\030\001 \001(\010:\004true\0223\n\014scale_filler\030\002 \001(\0132\035.o" "pencv_caffe.FillerParameter\022\034\n\016channel_s" "hared\030\003 \001(\010:\004true\022\022\n\003eps\030\004 \001(\002:\0051e-10\"\346\002" - "\n\021PriorBoxParameter\022\020\n\010min_size\030\001 \001(\002\022\020\n" - "\010max_size\030\002 \001(\002\022\024\n\014aspect_ratio\030\003 \003(\002\022\022\n" + "\n\021PriorBoxParameter\022\020\n\010min_size\030\001 \003(\002\022\020\n" + "\010max_size\030\002 \003(\002\022\024\n\014aspect_ratio\030\003 \003(\002\022\022\n" "\004flip\030\004 \001(\010:\004true\022\022\n\004clip\030\005 \001(\010:\004true\022\020\n" "\010variance\030\006 \003(\002\022\020\n\010img_size\030\007 \001(\r\022\r\n\005img" "_h\030\010 \001(\r\022\r\n\005img_w\030\t \001(\r\022\014\n\004step\030\n \001(\002\022\016\n" @@ -6600,6 +6600,8 @@ PriorBoxParameter::PriorBoxParameter(const PriorBoxParameter& from) _internal_metadata_(NULL), _has_bits_(from._has_bits_), _cached_size_(0), + min_size_(from.min_size_), + max_size_(from.max_size_), aspect_ratio_(from.aspect_ratio_), variance_(from.variance_), offset_h_(from.offset_h_), @@ -6607,17 +6609,17 @@ PriorBoxParameter::PriorBoxParameter(const PriorBoxParameter& from) width_(from.width_), height_(from.height_) { _internal_metadata_.MergeFrom(from._internal_metadata_); - ::memcpy(&min_size_, &from.min_size_, + ::memcpy(&img_size_, &from.img_size_, static_cast(reinterpret_cast(&offset_) - - reinterpret_cast(&min_size_)) + sizeof(offset_)); + reinterpret_cast(&img_size_)) + sizeof(offset_)); // @@protoc_insertion_point(copy_constructor:opencv_caffe.PriorBoxParameter) } void PriorBoxParameter::SharedCtor() { _cached_size_ = 0; - ::memset(&min_size_, 0, static_cast( + ::memset(&img_size_, 0, static_cast( reinterpret_cast(&step_w_) - - reinterpret_cast(&min_size_)) + sizeof(step_w_)); + reinterpret_cast(&img_size_)) + sizeof(step_w_)); flip_ = true; clip_ = true; offset_ = 0.5f; @@ -6660,6 +6662,8 @@ void PriorBoxParameter::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; + min_size_.Clear(); + max_size_.Clear(); aspect_ratio_.Clear(); variance_.Clear(); offset_h_.Clear(); @@ -6668,15 +6672,13 @@ void PriorBoxParameter::Clear() { height_.Clear(); cached_has_bits = _has_bits_[0]; if (cached_has_bits & 255u) { - ::memset(&min_size_, 0, static_cast( + ::memset(&img_size_, 0, static_cast( reinterpret_cast(&step_w_) - - reinterpret_cast(&min_size_)) + sizeof(step_w_)); - } - if (cached_has_bits & 1792u) { + reinterpret_cast(&img_size_)) + sizeof(step_w_)); flip_ = true; clip_ = true; - offset_ = 0.5f; } + offset_ = 0.5f; _has_bits_.Clear(); _internal_metadata_.Clear(); } @@ -6691,28 +6693,38 @@ bool PriorBoxParameter::MergePartialFromCodedStream( tag = p.first; if (!p.second) goto handle_unusual; switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional float min_size = 1; + // repeated float min_size = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(13u /* 13 & 0xFF */)) { - set_has_min_size(); - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive< float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>( - input, &min_size_))); + 1, 13u, input, this->mutable_min_size()))); + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline< + float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>( + input, this->mutable_min_size()))); } else { goto handle_unusual; } break; } - // optional float max_size = 2; + // repeated float max_size = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(21u /* 21 & 0xFF */)) { - set_has_max_size(); - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive< + float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>( + 1, 21u, input, this->mutable_max_size()))); + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline< float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>( - input, &max_size_))); + input, this->mutable_max_size()))); } else { goto handle_unusual; } @@ -6985,15 +6997,16 @@ void PriorBoxParameter::SerializeWithCachedSizes( ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; - cached_has_bits = _has_bits_[0]; - // optional float min_size = 1; - if (cached_has_bits & 0x00000001u) { - ::google::protobuf::internal::WireFormatLite::WriteFloat(1, this->min_size(), output); + // repeated float min_size = 1; + for (int i = 0, n = this->min_size_size(); i < n; i++) { + ::google::protobuf::internal::WireFormatLite::WriteFloat( + 1, this->min_size(i), output); } - // optional float max_size = 2; - if (cached_has_bits & 0x00000002u) { - ::google::protobuf::internal::WireFormatLite::WriteFloat(2, this->max_size(), output); + // repeated float max_size = 2; + for (int i = 0, n = this->max_size_size(); i < n; i++) { + ::google::protobuf::internal::WireFormatLite::WriteFloat( + 2, this->max_size(i), output); } // repeated float aspect_ratio = 3; @@ -7002,13 +7015,14 @@ void PriorBoxParameter::SerializeWithCachedSizes( 3, this->aspect_ratio(i), output); } + cached_has_bits = _has_bits_[0]; // optional bool flip = 4 [default = true]; - if (cached_has_bits & 0x00000100u) { + if (cached_has_bits & 0x00000040u) { ::google::protobuf::internal::WireFormatLite::WriteBool(4, this->flip(), output); } // optional bool clip = 5 [default = true]; - if (cached_has_bits & 0x00000200u) { + if (cached_has_bits & 0x00000080u) { ::google::protobuf::internal::WireFormatLite::WriteBool(5, this->clip(), output); } @@ -7019,37 +7033,37 @@ void PriorBoxParameter::SerializeWithCachedSizes( } // optional uint32 img_size = 7; - if (cached_has_bits & 0x00000004u) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteUInt32(7, this->img_size(), output); } // optional uint32 img_h = 8; - if (cached_has_bits & 0x00000008u) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteUInt32(8, this->img_h(), output); } // optional uint32 img_w = 9; - if (cached_has_bits & 0x00000010u) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteUInt32(9, this->img_w(), output); } // optional float step = 10; - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteFloat(10, this->step(), output); } // optional float step_h = 11; - if (cached_has_bits & 0x00000040u) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormatLite::WriteFloat(11, this->step_h(), output); } // optional float step_w = 12; - if (cached_has_bits & 0x00000080u) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormatLite::WriteFloat(12, this->step_w(), output); } // optional float offset = 13 [default = 0.5]; - if (cached_has_bits & 0x00000400u) { + if (cached_has_bits & 0x00000100u) { ::google::protobuf::internal::WireFormatLite::WriteFloat(13, this->offset(), output); } @@ -7091,28 +7105,26 @@ void PriorBoxParameter::SerializeWithCachedSizes( ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; - cached_has_bits = _has_bits_[0]; - // optional float min_size = 1; - if (cached_has_bits & 0x00000001u) { - target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(1, this->min_size(), target); - } + // repeated float min_size = 1; + target = ::google::protobuf::internal::WireFormatLite:: + WriteFloatToArray(1, this->min_size_, target); - // optional float max_size = 2; - if (cached_has_bits & 0x00000002u) { - target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(2, this->max_size(), target); - } + // repeated float max_size = 2; + target = ::google::protobuf::internal::WireFormatLite:: + WriteFloatToArray(2, this->max_size_, target); // repeated float aspect_ratio = 3; target = ::google::protobuf::internal::WireFormatLite:: WriteFloatToArray(3, this->aspect_ratio_, target); + cached_has_bits = _has_bits_[0]; // optional bool flip = 4 [default = true]; - if (cached_has_bits & 0x00000100u) { + if (cached_has_bits & 0x00000040u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(4, this->flip(), target); } // optional bool clip = 5 [default = true]; - if (cached_has_bits & 0x00000200u) { + if (cached_has_bits & 0x00000080u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(5, this->clip(), target); } @@ -7121,37 +7133,37 @@ void PriorBoxParameter::SerializeWithCachedSizes( WriteFloatToArray(6, this->variance_, target); // optional uint32 img_size = 7; - if (cached_has_bits & 0x00000004u) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(7, this->img_size(), target); } // optional uint32 img_h = 8; - if (cached_has_bits & 0x00000008u) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(8, this->img_h(), target); } // optional uint32 img_w = 9; - if (cached_has_bits & 0x00000010u) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(9, this->img_w(), target); } // optional float step = 10; - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(10, this->step(), target); } // optional float step_h = 11; - if (cached_has_bits & 0x00000040u) { + if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(11, this->step_h(), target); } // optional float step_w = 12; - if (cached_has_bits & 0x00000080u) { + if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(12, this->step_w(), target); } // optional float offset = 13 [default = 0.5]; - if (cached_has_bits & 0x00000400u) { + if (cached_has_bits & 0x00000100u) { target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(13, this->offset(), target); } @@ -7188,6 +7200,24 @@ size_t PriorBoxParameter::ByteSizeLong() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( _internal_metadata_.unknown_fields()); } + // repeated float min_size = 1; + { + unsigned int count = static_cast(this->min_size_size()); + size_t data_size = 4UL * count; + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->min_size_size()); + total_size += data_size; + } + + // repeated float max_size = 2; + { + unsigned int count = static_cast(this->max_size_size()); + size_t data_size = 4UL * count; + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->max_size_size()); + total_size += data_size; + } + // repeated float aspect_ratio = 3; { unsigned int count = static_cast(this->aspect_ratio_size()); @@ -7243,16 +7273,6 @@ size_t PriorBoxParameter::ByteSizeLong() const { } if (_has_bits_[0 / 32] & 255u) { - // optional float min_size = 1; - if (has_min_size()) { - total_size += 1 + 4; - } - - // optional float max_size = 2; - if (has_max_size()) { - total_size += 1 + 4; - } - // optional uint32 img_size = 7; if (has_img_size()) { total_size += 1 + @@ -7289,8 +7309,6 @@ size_t PriorBoxParameter::ByteSizeLong() const { total_size += 1 + 4; } - } - if (_has_bits_[8 / 32] & 1792u) { // optional bool flip = 4 [default = true]; if (has_flip()) { total_size += 1 + 1; @@ -7301,12 +7319,12 @@ size_t PriorBoxParameter::ByteSizeLong() const { total_size += 1 + 1; } - // optional float offset = 13 [default = 0.5]; - if (has_offset()) { - total_size += 1 + 4; - } - } + // optional float offset = 13 [default = 0.5]; + if (has_offset()) { + total_size += 1 + 4; + } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = cached_size; @@ -7336,6 +7354,8 @@ void PriorBoxParameter::MergeFrom(const PriorBoxParameter& from) { ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; + min_size_.MergeFrom(from.min_size_); + max_size_.MergeFrom(from.max_size_); aspect_ratio_.MergeFrom(from.aspect_ratio_); variance_.MergeFrom(from.variance_); offset_h_.MergeFrom(from.offset_h_); @@ -7345,43 +7365,34 @@ void PriorBoxParameter::MergeFrom(const PriorBoxParameter& from) { cached_has_bits = from._has_bits_[0]; if (cached_has_bits & 255u) { if (cached_has_bits & 0x00000001u) { - min_size_ = from.min_size_; - } - if (cached_has_bits & 0x00000002u) { - max_size_ = from.max_size_; - } - if (cached_has_bits & 0x00000004u) { img_size_ = from.img_size_; } - if (cached_has_bits & 0x00000008u) { + if (cached_has_bits & 0x00000002u) { img_h_ = from.img_h_; } - if (cached_has_bits & 0x00000010u) { + if (cached_has_bits & 0x00000004u) { img_w_ = from.img_w_; } - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000008u) { step_ = from.step_; } - if (cached_has_bits & 0x00000040u) { + if (cached_has_bits & 0x00000010u) { step_h_ = from.step_h_; } - if (cached_has_bits & 0x00000080u) { + if (cached_has_bits & 0x00000020u) { step_w_ = from.step_w_; } - _has_bits_[0] |= cached_has_bits; - } - if (cached_has_bits & 1792u) { - if (cached_has_bits & 0x00000100u) { + if (cached_has_bits & 0x00000040u) { flip_ = from.flip_; } - if (cached_has_bits & 0x00000200u) { + if (cached_has_bits & 0x00000080u) { clip_ = from.clip_; } - if (cached_has_bits & 0x00000400u) { - offset_ = from.offset_; - } _has_bits_[0] |= cached_has_bits; } + if (cached_has_bits & 0x00000100u) { + set_offset(from.offset()); + } } void PriorBoxParameter::CopyFrom(const ::google::protobuf::Message& from) { @@ -7408,14 +7419,14 @@ void PriorBoxParameter::Swap(PriorBoxParameter* other) { } void PriorBoxParameter::InternalSwap(PriorBoxParameter* other) { using std::swap; + min_size_.InternalSwap(&other->min_size_); + max_size_.InternalSwap(&other->max_size_); aspect_ratio_.InternalSwap(&other->aspect_ratio_); variance_.InternalSwap(&other->variance_); offset_h_.InternalSwap(&other->offset_h_); offset_w_.InternalSwap(&other->offset_w_); width_.InternalSwap(&other->width_); height_.InternalSwap(&other->height_); - swap(min_size_, other->min_size_); - swap(max_size_, other->max_size_); swap(img_size_, other->img_size_); swap(img_h_, other->img_h_); swap(img_w_, other->img_w_); diff --git a/modules/dnn/misc/caffe/opencv-caffe.pb.h b/modules/dnn/misc/caffe/opencv-caffe.pb.h index 1920cf8e89..923ca7fb1f 100644 --- a/modules/dnn/misc/caffe/opencv-caffe.pb.h +++ b/modules/dnn/misc/caffe/opencv-caffe.pb.h @@ -1886,6 +1886,30 @@ class PriorBoxParameter : public ::google::protobuf::Message /* @@protoc_inserti // accessors ------------------------------------------------------- + // repeated float min_size = 1; + int min_size_size() const; + void clear_min_size(); + static const int kMinSizeFieldNumber = 1; + float min_size(int index) const; + void set_min_size(int index, float value); + void add_min_size(float value); + const ::google::protobuf::RepeatedField< float >& + min_size() const; + ::google::protobuf::RepeatedField< float >* + mutable_min_size(); + + // repeated float max_size = 2; + int max_size_size() const; + void clear_max_size(); + static const int kMaxSizeFieldNumber = 2; + float max_size(int index) const; + void set_max_size(int index, float value); + void add_max_size(float value); + const ::google::protobuf::RepeatedField< float >& + max_size() const; + ::google::protobuf::RepeatedField< float >* + mutable_max_size(); + // repeated float aspect_ratio = 3; int aspect_ratio_size() const; void clear_aspect_ratio(); @@ -1958,20 +1982,6 @@ class PriorBoxParameter : public ::google::protobuf::Message /* @@protoc_inserti ::google::protobuf::RepeatedField< float >* mutable_height(); - // optional float min_size = 1; - bool has_min_size() const; - void clear_min_size(); - static const int kMinSizeFieldNumber = 1; - float min_size() const; - void set_min_size(float value); - - // optional float max_size = 2; - bool has_max_size() const; - void clear_max_size(); - static const int kMaxSizeFieldNumber = 2; - float max_size() const; - void set_max_size(float value); - // optional uint32 img_size = 7; bool has_img_size() const; void clear_img_size(); @@ -2037,10 +2047,6 @@ class PriorBoxParameter : public ::google::protobuf::Message /* @@protoc_inserti // @@protoc_insertion_point(class_scope:opencv_caffe.PriorBoxParameter) private: - void set_has_min_size(); - void clear_has_min_size(); - void set_has_max_size(); - void clear_has_max_size(); void set_has_flip(); void clear_has_flip(); void set_has_clip(); @@ -2063,14 +2069,14 @@ class PriorBoxParameter : public ::google::protobuf::Message /* @@protoc_inserti ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; + ::google::protobuf::RepeatedField< float > min_size_; + ::google::protobuf::RepeatedField< float > max_size_; ::google::protobuf::RepeatedField< float > aspect_ratio_; ::google::protobuf::RepeatedField< float > variance_; ::google::protobuf::RepeatedField< float > offset_h_; ::google::protobuf::RepeatedField< float > offset_w_; ::google::protobuf::RepeatedField< float > width_; ::google::protobuf::RepeatedField< float > height_; - float min_size_; - float max_size_; ::google::protobuf::uint32 img_size_; ::google::protobuf::uint32 img_h_; ::google::protobuf::uint32 img_w_; @@ -15271,53 +15277,65 @@ inline void NormalizeBBoxParameter::set_eps(float value) { // PriorBoxParameter -// optional float min_size = 1; -inline bool PriorBoxParameter::has_min_size() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PriorBoxParameter::set_has_min_size() { - _has_bits_[0] |= 0x00000001u; -} -inline void PriorBoxParameter::clear_has_min_size() { - _has_bits_[0] &= ~0x00000001u; +// repeated float min_size = 1; +inline int PriorBoxParameter::min_size_size() const { + return min_size_.size(); } inline void PriorBoxParameter::clear_min_size() { - min_size_ = 0; - clear_has_min_size(); + min_size_.Clear(); } -inline float PriorBoxParameter::min_size() const { +inline float PriorBoxParameter::min_size(int index) const { // @@protoc_insertion_point(field_get:opencv_caffe.PriorBoxParameter.min_size) - return min_size_; + return min_size_.Get(index); } -inline void PriorBoxParameter::set_min_size(float value) { - set_has_min_size(); - min_size_ = value; +inline void PriorBoxParameter::set_min_size(int index, float value) { + min_size_.Set(index, value); // @@protoc_insertion_point(field_set:opencv_caffe.PriorBoxParameter.min_size) } - -// optional float max_size = 2; -inline bool PriorBoxParameter::has_max_size() const { - return (_has_bits_[0] & 0x00000002u) != 0; +inline void PriorBoxParameter::add_min_size(float value) { + min_size_.Add(value); + // @@protoc_insertion_point(field_add:opencv_caffe.PriorBoxParameter.min_size) } -inline void PriorBoxParameter::set_has_max_size() { - _has_bits_[0] |= 0x00000002u; +inline const ::google::protobuf::RepeatedField< float >& +PriorBoxParameter::min_size() const { + // @@protoc_insertion_point(field_list:opencv_caffe.PriorBoxParameter.min_size) + return min_size_; } -inline void PriorBoxParameter::clear_has_max_size() { - _has_bits_[0] &= ~0x00000002u; +inline ::google::protobuf::RepeatedField< float >* +PriorBoxParameter::mutable_min_size() { + // @@protoc_insertion_point(field_mutable_list:opencv_caffe.PriorBoxParameter.min_size) + return &min_size_; +} + +// repeated float max_size = 2; +inline int PriorBoxParameter::max_size_size() const { + return max_size_.size(); } inline void PriorBoxParameter::clear_max_size() { - max_size_ = 0; - clear_has_max_size(); + max_size_.Clear(); } -inline float PriorBoxParameter::max_size() const { +inline float PriorBoxParameter::max_size(int index) const { // @@protoc_insertion_point(field_get:opencv_caffe.PriorBoxParameter.max_size) - return max_size_; + return max_size_.Get(index); } -inline void PriorBoxParameter::set_max_size(float value) { - set_has_max_size(); - max_size_ = value; +inline void PriorBoxParameter::set_max_size(int index, float value) { + max_size_.Set(index, value); // @@protoc_insertion_point(field_set:opencv_caffe.PriorBoxParameter.max_size) } +inline void PriorBoxParameter::add_max_size(float value) { + max_size_.Add(value); + // @@protoc_insertion_point(field_add:opencv_caffe.PriorBoxParameter.max_size) +} +inline const ::google::protobuf::RepeatedField< float >& +PriorBoxParameter::max_size() const { + // @@protoc_insertion_point(field_list:opencv_caffe.PriorBoxParameter.max_size) + return max_size_; +} +inline ::google::protobuf::RepeatedField< float >* +PriorBoxParameter::mutable_max_size() { + // @@protoc_insertion_point(field_mutable_list:opencv_caffe.PriorBoxParameter.max_size) + return &max_size_; +} // repeated float aspect_ratio = 3; inline int PriorBoxParameter::aspect_ratio_size() const { @@ -15351,13 +15369,13 @@ PriorBoxParameter::mutable_aspect_ratio() { // optional bool flip = 4 [default = true]; inline bool PriorBoxParameter::has_flip() const { - return (_has_bits_[0] & 0x00000100u) != 0; + return (_has_bits_[0] & 0x00000040u) != 0; } inline void PriorBoxParameter::set_has_flip() { - _has_bits_[0] |= 0x00000100u; + _has_bits_[0] |= 0x00000040u; } inline void PriorBoxParameter::clear_has_flip() { - _has_bits_[0] &= ~0x00000100u; + _has_bits_[0] &= ~0x00000040u; } inline void PriorBoxParameter::clear_flip() { flip_ = true; @@ -15375,13 +15393,13 @@ inline void PriorBoxParameter::set_flip(bool value) { // optional bool clip = 5 [default = true]; inline bool PriorBoxParameter::has_clip() const { - return (_has_bits_[0] & 0x00000200u) != 0; + return (_has_bits_[0] & 0x00000080u) != 0; } inline void PriorBoxParameter::set_has_clip() { - _has_bits_[0] |= 0x00000200u; + _has_bits_[0] |= 0x00000080u; } inline void PriorBoxParameter::clear_has_clip() { - _has_bits_[0] &= ~0x00000200u; + _has_bits_[0] &= ~0x00000080u; } inline void PriorBoxParameter::clear_clip() { clip_ = true; @@ -15429,13 +15447,13 @@ PriorBoxParameter::mutable_variance() { // optional uint32 img_size = 7; inline bool PriorBoxParameter::has_img_size() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000001u) != 0; } inline void PriorBoxParameter::set_has_img_size() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000001u; } inline void PriorBoxParameter::clear_has_img_size() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000001u; } inline void PriorBoxParameter::clear_img_size() { img_size_ = 0u; @@ -15453,13 +15471,13 @@ inline void PriorBoxParameter::set_img_size(::google::protobuf::uint32 value) { // optional uint32 img_h = 8; inline bool PriorBoxParameter::has_img_h() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } inline void PriorBoxParameter::set_has_img_h() { - _has_bits_[0] |= 0x00000008u; + _has_bits_[0] |= 0x00000002u; } inline void PriorBoxParameter::clear_has_img_h() { - _has_bits_[0] &= ~0x00000008u; + _has_bits_[0] &= ~0x00000002u; } inline void PriorBoxParameter::clear_img_h() { img_h_ = 0u; @@ -15477,13 +15495,13 @@ inline void PriorBoxParameter::set_img_h(::google::protobuf::uint32 value) { // optional uint32 img_w = 9; inline bool PriorBoxParameter::has_img_w() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } inline void PriorBoxParameter::set_has_img_w() { - _has_bits_[0] |= 0x00000010u; + _has_bits_[0] |= 0x00000004u; } inline void PriorBoxParameter::clear_has_img_w() { - _has_bits_[0] &= ~0x00000010u; + _has_bits_[0] &= ~0x00000004u; } inline void PriorBoxParameter::clear_img_w() { img_w_ = 0u; @@ -15501,13 +15519,13 @@ inline void PriorBoxParameter::set_img_w(::google::protobuf::uint32 value) { // optional float step = 10; inline bool PriorBoxParameter::has_step() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } inline void PriorBoxParameter::set_has_step() { - _has_bits_[0] |= 0x00000020u; + _has_bits_[0] |= 0x00000008u; } inline void PriorBoxParameter::clear_has_step() { - _has_bits_[0] &= ~0x00000020u; + _has_bits_[0] &= ~0x00000008u; } inline void PriorBoxParameter::clear_step() { step_ = 0; @@ -15525,13 +15543,13 @@ inline void PriorBoxParameter::set_step(float value) { // optional float step_h = 11; inline bool PriorBoxParameter::has_step_h() const { - return (_has_bits_[0] & 0x00000040u) != 0; + return (_has_bits_[0] & 0x00000010u) != 0; } inline void PriorBoxParameter::set_has_step_h() { - _has_bits_[0] |= 0x00000040u; + _has_bits_[0] |= 0x00000010u; } inline void PriorBoxParameter::clear_has_step_h() { - _has_bits_[0] &= ~0x00000040u; + _has_bits_[0] &= ~0x00000010u; } inline void PriorBoxParameter::clear_step_h() { step_h_ = 0; @@ -15549,13 +15567,13 @@ inline void PriorBoxParameter::set_step_h(float value) { // optional float step_w = 12; inline bool PriorBoxParameter::has_step_w() const { - return (_has_bits_[0] & 0x00000080u) != 0; + return (_has_bits_[0] & 0x00000020u) != 0; } inline void PriorBoxParameter::set_has_step_w() { - _has_bits_[0] |= 0x00000080u; + _has_bits_[0] |= 0x00000020u; } inline void PriorBoxParameter::clear_has_step_w() { - _has_bits_[0] &= ~0x00000080u; + _has_bits_[0] &= ~0x00000020u; } inline void PriorBoxParameter::clear_step_w() { step_w_ = 0; @@ -15573,13 +15591,13 @@ inline void PriorBoxParameter::set_step_w(float value) { // optional float offset = 13 [default = 0.5]; inline bool PriorBoxParameter::has_offset() const { - return (_has_bits_[0] & 0x00000400u) != 0; + return (_has_bits_[0] & 0x00000100u) != 0; } inline void PriorBoxParameter::set_has_offset() { - _has_bits_[0] |= 0x00000400u; + _has_bits_[0] |= 0x00000100u; } inline void PriorBoxParameter::clear_has_offset() { - _has_bits_[0] &= ~0x00000400u; + _has_bits_[0] &= ~0x00000100u; } inline void PriorBoxParameter::clear_offset() { offset_ = 0.5f; diff --git a/modules/dnn/src/caffe/opencv-caffe.proto b/modules/dnn/src/caffe/opencv-caffe.proto index 380b51f281..8ab35bac99 100644 --- a/modules/dnn/src/caffe/opencv-caffe.proto +++ b/modules/dnn/src/caffe/opencv-caffe.proto @@ -116,9 +116,9 @@ message PriorBoxParameter { CENTER_SIZE = 2; } // Minimum box size (in pixels). Required! - optional float min_size = 1; + repeated float min_size = 1; // Maximum box size (in pixels). Required! - optional float max_size = 2; + repeated float max_size = 2; // Various of aspect ratios. Duplicate ratios will be ignored. // If none is provided, we use default ratio 1. repeated float aspect_ratio = 3; diff --git a/modules/dnn/src/layers/prior_box_layer.cpp b/modules/dnn/src/layers/prior_box_layer.cpp index dc949d0fba..4e0a6e018f 100644 --- a/modules/dnn/src/layers/prior_box_layer.cpp +++ b/modules/dnn/src/layers/prior_box_layer.cpp @@ -180,21 +180,20 @@ public: PriorBoxLayerImpl(const LayerParams ¶ms) { setParamsFrom(params); - _minSize = getParameter(params, "min_size", 0, false, 0); _flip = getParameter(params, "flip", 0, false, true); _clip = getParameter(params, "clip", 0, false, true); _bboxesNormalized = getParameter(params, "normalized_bbox", 0, false, true); - _aspectRatios.clear(); - + getParams("min_size", params, &_minSize); getAspectRatios(params); getVariance(params); - _maxSize = -1; if (params.has("max_size")) { - _maxSize = params.get("max_size").get(0); - CV_Assert(_maxSize > _minSize); + getParams("max_size", params, &_maxSize); + CV_Assert(_minSize.size() == _maxSize.size()); + for (int i = 0; i < _maxSize.size(); i++) + CV_Assert(_minSize[i] < _maxSize[i]); } std::vector widths, heights; @@ -213,25 +212,28 @@ public: } else { - CV_Assert(_minSize > 0); - _boxWidths.resize(1 + (_maxSize > 0 ? 1 : 0) + _aspectRatios.size()); - _boxHeights.resize(_boxWidths.size()); - _boxWidths[0] = _boxHeights[0] = _minSize; - - int i = 1; - if (_maxSize > 0) + CV_Assert(!_minSize.empty()); + for (int i = 0; i < _minSize.size(); ++i) { - // second prior: aspect_ratio = 1, size = sqrt(min_size * max_size) - _boxWidths[i] = _boxHeights[i] = sqrt(_minSize * _maxSize); - i += 1; - } + float minSize = _minSize[i]; + CV_Assert(minSize > 0); + _boxWidths.push_back(minSize); + _boxHeights.push_back(minSize); - // rest of priors - for (size_t r = 0; r < _aspectRatios.size(); ++r) - { - float arSqrt = sqrt(_aspectRatios[r]); - _boxWidths[i + r] = _minSize * arSqrt; - _boxHeights[i + r] = _minSize / arSqrt; + if (_maxSize.size() > 0) + { + float size = sqrt(minSize * _maxSize[i]); + _boxWidths.push_back(size); + _boxHeights.push_back(size); + } + + // rest of priors + for (size_t r = 0; r < _aspectRatios.size(); ++r) + { + float arSqrt = sqrt(_aspectRatios[r]); + _boxWidths.push_back(minSize * arSqrt); + _boxHeights.push_back(minSize / arSqrt); + } } } CV_Assert(_boxWidths.size() == _boxHeights.size()); @@ -271,7 +273,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { return backendId == DNN_BACKEND_OPENCV || - (backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine()); + (backendId == DNN_BACKEND_INFERENCE_ENGINE && haveInfEngine() && + ( _explicitSizes || (_minSize.size() == 1 && _maxSize.size() <= 1))); } bool getMemoryShapes(const std::vector &inputs, @@ -508,10 +511,9 @@ public: InferenceEngine::Builder::PriorBoxLayer ieLayer(name); CV_Assert(!_explicitSizes); - - ieLayer.setMinSize(_minSize); - if (_maxSize > 0) - ieLayer.setMaxSize(_maxSize); + ieLayer.setMinSize(_minSize[0]); + if (!_maxSize.empty()) + ieLayer.setMaxSize(_maxSize[0]); CV_CheckEQ(_offsetsX.size(), (size_t)1, ""); CV_CheckEQ(_offsetsY.size(), (size_t)1, ""); CV_CheckEQ(_offsetsX[0], _offsetsY[0], ""); ieLayer.setOffset(_offsetsX[0]); @@ -558,8 +560,8 @@ public: } private: - float _minSize; - float _maxSize; + std::vector _minSize; + std::vector _maxSize; float _stepX, _stepY; diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 02d33b4c36..fabe4d4b89 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -742,6 +742,22 @@ TEST_P(Test_Caffe_layers, Average_pooling_kernel_area) normAssert(out, blobFromImage(ref)); } +TEST_P(Test_Caffe_layers, PriorBox_repeated) +{ + Net net = readNet(_tf("prior_box.prototxt")); + int inp_size[] = {1, 3, 10, 10}; + int shape_size[] = {1, 2, 3, 4}; + Mat inp(4, inp_size, CV_32F); + randu(inp, -1.0f, 1.0f); + Mat shape(4, shape_size, CV_32F); + randu(shape, -1.0f, 1.0f); + net.setInput(inp, "data"); + net.setInput(shape, "shape"); + Mat out = net.forward(); + Mat ref = blobFromNPY(_tf("priorbox_output.npy")); + normAssert(out, ref, ""); +} + // Test PriorBoxLayer in case of no aspect ratios (just squared proposals). TEST_P(Test_Caffe_layers, PriorBox_squares) { From d3cf0d2c06009f5adf9aff094cf95233c61fa956 Mon Sep 17 00:00:00 2001 From: dcouwenh <47040981+dcouwenh@users.noreply.github.com> Date: Tue, 30 Jul 2019 16:49:46 -0400 Subject: [PATCH 10/23] Bayer VNG Demosaicing Fix #2 (Merge pull request #15086) * Update demosaicing.cpp Fixed calculation of Bs for non-green pixels. * Fixed cvtColor perf test for bayer VNG --- modules/imgproc/perf/perf_cvt_color.cpp | 2 +- modules/imgproc/src/demosaicing.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/imgproc/perf/perf_cvt_color.cpp b/modules/imgproc/perf/perf_cvt_color.cpp index e3af113bed..ab169ecfca 100644 --- a/modules/imgproc/perf/perf_cvt_color.cpp +++ b/modules/imgproc/perf/perf_cvt_color.cpp @@ -417,7 +417,7 @@ PERF_TEST_P(Size_CvtMode_Bayer, cvtColorBayer8u, TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn); - SANITY_CHECK(dst, 1); + SANITY_CHECK_NOTHING(); } typedef tuple Size_CvtMode2_t; diff --git a/modules/imgproc/src/demosaicing.cpp b/modules/imgproc/src/demosaicing.cpp index 9162e35fdf..a14b6d7905 100644 --- a/modules/imgproc/src/demosaicing.cpp +++ b/modules/imgproc/src/demosaicing.cpp @@ -1153,14 +1153,14 @@ static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code ) { Rs += srow[-bstep*2-2] + srow[0]; Gs += brow0[N6-1]; - Bs += srow[-bstep+1]*2; + Bs += srow[-bstep-1]*2; ng++; } if( gradSE < T ) { Rs += srow[bstep*2+2] + srow[0]; Gs += brow2[N6+1]; - Bs += srow[-bstep+1]*2; + Bs += srow[bstep+1]*2; ng++; } R = srow[0]; @@ -1394,8 +1394,8 @@ static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code ) RGs = _mm_adds_epi16(RGs, _mm_and_si128(_mm_merge_epi16(t1, t0), mask)); // GRs += {brow2[N6+1]; (srow[1]+srow[bstep*2+1])} * (T>gradSE) GRs = _mm_adds_epi16(GRs, _mm_and_si128(_mm_merge_epi16(_mm_loadu_si128((__m128i*)(brow2+N6+1)), _mm_adds_epi16(x7,x10)), mask)); - // Bs += {srow[-bstep+1]*2; (srow[bstep+2]+srow[bstep])} * (T>gradSE) - Bs = _mm_adds_epi16(Bs, _mm_and_si128(_mm_merge_epi16(_mm_slli_epi16(x5, 1), _mm_adds_epi16(x8,x11)), mask)); + // Bs += {srow[bstep+1]*2; (srow[bstep+2]+srow[bstep])} * (T>gradSE) + Bs = _mm_adds_epi16(Bs, _mm_and_si128(_mm_merge_epi16(_mm_slli_epi16(x9, 1), _mm_adds_epi16(x8,x11)), mask)); // gradS *********************************************** mask = _mm_cmpgt_epi16(T, gradS); // mask = T>gradS @@ -1451,7 +1451,7 @@ static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code ) // GRs += {brow0[N6-1]; (srow[-bstep*2-1]+srow[-1])} * (T>gradNW) GRs = _mm_adds_epi16(GRs, _mm_and_si128(_mm_merge_epi16(_mm_loadu_si128((__m128i*)(brow0+N6-1)), _mm_adds_epi16(x2,x15)), mask)); // Bs += {srow[-bstep-1]*2; (srow[-bstep]+srow[-bstep-2])} * (T>gradNW) - Bs = _mm_adds_epi16(Bs, _mm_and_si128(_mm_merge_epi16(_mm_slli_epi16(x5, 1),_mm_adds_epi16(x3,x16)), mask)); + Bs = _mm_adds_epi16(Bs, _mm_and_si128(_mm_merge_epi16(_mm_slli_epi16(x1, 1),_mm_adds_epi16(x3,x16)), mask)); __m128 ngf0 = _mm_div_ps(_0_5, _mm_cvtloepi16_ps(ng)); __m128 ngf1 = _mm_div_ps(_0_5, _mm_cvthiepi16_ps(ng)); From 1275248f39648111a5e77b5c52cecb7449cf8e86 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 31 Jul 2019 15:16:23 +0300 Subject: [PATCH 11/23] PCH: disable by default on all platforms except MSVC --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ce583bc69..43b0060938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,7 +475,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar # OpenCV build options # =================================================== OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) ) -OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) ) +OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) ) OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) ) OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC ) OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CV_GCC ) From 6d5ac67681bece7799797117783abb7b7d93f0b9 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 31 Jul 2019 15:41:22 +0300 Subject: [PATCH 12/23] Restored IPP call reduction --- modules/core/src/matrix_operations.cpp | 5 +++++ modules/core/src/mean.dispatch.cpp | 6 ++++++ modules/core/src/minmax.cpp | 6 ++++++ modules/core/src/sum.dispatch.cpp | 6 ++++++ modules/imgproc/src/box_filter.dispatch.cpp | 4 ++-- modules/imgproc/src/corner.cpp | 6 +++--- modules/imgproc/src/deriv.cpp | 6 +++--- modules/imgproc/src/filter.dispatch.cpp | 6 +++--- modules/imgproc/src/median_blur.dispatch.cpp | 4 ++-- modules/imgproc/src/morph.dispatch.cpp | 10 +++++----- modules/imgproc/src/smooth.dispatch.cpp | 4 ++-- 11 files changed, 43 insertions(+), 20 deletions(-) diff --git a/modules/core/src/matrix_operations.cpp b/modules/core/src/matrix_operations.cpp index 6d865a51a9..22ed50cf19 100644 --- a/modules/core/src/matrix_operations.cpp +++ b/modules/core/src/matrix_operations.cpp @@ -8,6 +8,11 @@ #include "opencl_kernels_core.hpp" #include "precomp.hpp" +#undef HAVE_IPP +#undef CV_IPP_RUN_FAST +#define CV_IPP_RUN_FAST(f, ...) +#undef CV_IPP_RUN +#define CV_IPP_RUN(c, f, ...) /*************************************************************************************************\ Matrix Operations diff --git a/modules/core/src/mean.dispatch.cpp b/modules/core/src/mean.dispatch.cpp index 33dc81a00e..ae59fe3a47 100644 --- a/modules/core/src/mean.dispatch.cpp +++ b/modules/core/src/mean.dispatch.cpp @@ -11,6 +11,12 @@ #include "mean.simd.hpp" #include "mean.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content +#undef HAVE_IPP +#undef CV_IPP_RUN_FAST +#define CV_IPP_RUN_FAST(f, ...) +#undef CV_IPP_RUN +#define CV_IPP_RUN(c, f, ...) + namespace cv { #if defined HAVE_IPP diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index 19ed119ad8..da75e20a1d 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -8,6 +8,12 @@ #include "opencv2/core/openvx/ovx_defs.hpp" #include "stat.hpp" +#undef HAVE_IPP +#undef CV_IPP_RUN_FAST +#define CV_IPP_RUN_FAST(f, ...) +#undef CV_IPP_RUN +#define CV_IPP_RUN(c, f, ...) + #define IPP_DISABLE_MINMAXIDX_MANY_ROWS 1 // see Core_MinMaxIdx.rows_overflow test /****************************************************************************************\ diff --git a/modules/core/src/sum.dispatch.cpp b/modules/core/src/sum.dispatch.cpp index 6ca5f9ded9..769ae513cf 100644 --- a/modules/core/src/sum.dispatch.cpp +++ b/modules/core/src/sum.dispatch.cpp @@ -10,6 +10,12 @@ #include "sum.simd.hpp" #include "sum.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content +#undef HAVE_IPP +#undef CV_IPP_RUN_FAST +#define CV_IPP_RUN_FAST(f, ...) +#undef CV_IPP_RUN +#define CV_IPP_RUN(c, f, ...) + namespace cv { diff --git a/modules/imgproc/src/box_filter.dispatch.cpp b/modules/imgproc/src/box_filter.dispatch.cpp index 154ccfd09e..054e7474c6 100644 --- a/modules/imgproc/src/box_filter.dispatch.cpp +++ b/modules/imgproc/src/box_filter.dispatch.cpp @@ -389,7 +389,7 @@ Ptr createBoxFilter(int srcType, int dstType, Size ksize, } #endif -#if defined(HAVE_IPP) +#if 0 //defined(HAVE_IPP) static bool ipp_boxfilter(Mat &src, Mat &dst, Size ksize, Point anchor, bool normalize, int borderType) { #ifdef HAVE_IPP_IW @@ -476,7 +476,7 @@ void boxFilter(InputArray _src, OutputArray _dst, int ddepth, CV_OVX_RUN(true, openvx_boxfilter(src, dst, ddepth, ksize, anchor, normalize, borderType)) - CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); + //CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); borderType = (borderType&~BORDER_ISOLATED); diff --git a/modules/imgproc/src/corner.cpp b/modules/imgproc/src/corner.cpp index 65ed84af95..501febc5c4 100644 --- a/modules/imgproc/src/corner.cpp +++ b/modules/imgproc/src/corner.cpp @@ -475,7 +475,7 @@ static bool ocl_preCornerDetect( InputArray _src, OutputArray _dst, int ksize, i } -#if defined(HAVE_IPP) +#if 0 //defined(HAVE_IPP) namespace cv { static bool ipp_cornerMinEigenVal( InputArray _src, OutputArray _dst, int blockSize, int ksize, int borderType ) @@ -558,7 +558,7 @@ void cv::cornerMinEigenVal( InputArray _src, OutputArray _dst, int blockSize, in CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat(), ocl_cornerMinEigenValVecs(_src, _dst, blockSize, ksize, 0.0, borderType, MINEIGENVAL)) -#ifdef HAVE_IPP +/*#ifdef HAVE_IPP int kerSize = (ksize < 0)?3:ksize; bool isolated = (borderType & BORDER_ISOLATED) != 0; int borderTypeNI = borderType & ~BORDER_ISOLATED; @@ -566,7 +566,7 @@ void cv::cornerMinEigenVal( InputArray _src, OutputArray _dst, int blockSize, in CV_IPP_RUN(((borderTypeNI == BORDER_REPLICATE && (!_src.isSubmatrix() || isolated)) && (kerSize == 3 || kerSize == 5) && (blockSize == 3 || blockSize == 5)) && IPP_VERSION_X100 >= 800, ipp_cornerMinEigenVal( _src, _dst, blockSize, ksize, borderType )); - + */ Mat src = _src.getMat(); _dst.create( src.size(), CV_32FC1 ); diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index f4095a1086..fa9defb405 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -260,7 +260,7 @@ namespace cv } #endif -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP namespace cv { @@ -457,7 +457,7 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, CV_OVX_RUN(true, openvx_sobel(src, dst, dx, dy, ksize, scale, delta, borderType)) - CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, ksize, scale, delta, borderType)); + //CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, ksize, scale, delta, borderType)); sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); } @@ -507,7 +507,7 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, CALL_HAL(scharr, cv_hal_scharr, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn, ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, dx, dy, scale, delta, borderType&~BORDER_ISOLATED); - CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, 0, scale, delta, borderType)); + //CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, 0, scale, delta, borderType)); sepFilter2D( src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); } diff --git a/modules/imgproc/src/filter.dispatch.cpp b/modules/imgproc/src/filter.dispatch.cpp index c21efe181c..60f13e37dd 100644 --- a/modules/imgproc/src/filter.dispatch.cpp +++ b/modules/imgproc/src/filter.dispatch.cpp @@ -1022,7 +1022,7 @@ static bool replacementFilter2D(int stype, int dtype, int kernel_type, return success; } -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP static bool ippFilter2D(int stype, int dtype, int kernel_type, uchar * src_data, size_t src_step, uchar * dst_data, size_t dst_step, @@ -1286,7 +1286,7 @@ void filter2D(int stype, int dtype, int kernel_type, if (res) return; - CV_IPP_RUN_FAST(ippFilter2D(stype, dtype, kernel_type, + /*CV_IPP_RUN_FAST(ippFilter2D(stype, dtype, kernel_type, src_data, src_step, dst_data, dst_step, width, height, @@ -1295,7 +1295,7 @@ void filter2D(int stype, int dtype, int kernel_type, kernel_data, kernel_step, kernel_width, kernel_height, anchor_x, anchor_y, - delta, borderType, isSubmatrix)) + delta, borderType, isSubmatrix))*/ res = dftFilter2D(stype, dtype, kernel_type, src_data, src_step, diff --git a/modules/imgproc/src/median_blur.dispatch.cpp b/modules/imgproc/src/median_blur.dispatch.cpp index d993fbad5b..79333f5f80 100644 --- a/modules/imgproc/src/median_blur.dispatch.cpp +++ b/modules/imgproc/src/median_blur.dispatch.cpp @@ -203,7 +203,7 @@ static bool openvx_medianFilter(InputArray _src, OutputArray _dst, int ksize) } #endif -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP static bool ipp_medianFilter(Mat &src0, Mat &dst, int ksize) { CV_INSTRUMENT_REGION_IPP(); @@ -301,7 +301,7 @@ void medianBlur( InputArray _src0, OutputArray _dst, int ksize ) CV_OVX_RUN(true, openvx_medianFilter(_src0, _dst, ksize)) - CV_IPP_RUN_FAST(ipp_medianFilter(src0, dst, ksize)); + //CV_IPP_RUN_FAST(ipp_medianFilter(src0, dst, ksize)); #ifdef HAVE_TEGRA_OPTIMIZATION if (tegra::useTegra() && tegra::medianBlur(src0, dst, ksize)) diff --git a/modules/imgproc/src/morph.dispatch.cpp b/modules/imgproc/src/morph.dispatch.cpp index 326bc66593..441797ce88 100644 --- a/modules/imgproc/src/morph.dispatch.cpp +++ b/modules/imgproc/src/morph.dispatch.cpp @@ -221,7 +221,7 @@ static bool halMorph(int op, int src_type, int dst_type, } // ===== 2. IPP implementation -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP #ifdef HAVE_IPP_IW static inline IwiMorphologyType ippiGetMorphologyType(int morphOp) { @@ -495,12 +495,12 @@ void morph(int op, int src_type, int dst_type, return; } - CV_IPP_RUN_FAST(ippMorph(op, src_type, dst_type, src_data, src_step, dst_data, dst_step, width, height, + /*CV_IPP_RUN_FAST(ippMorph(op, src_type, dst_type, src_data, src_step, dst_data, dst_step, width, height, roi_width, roi_height, roi_x, roi_y, roi_width2, roi_height2, roi_x2, roi_y2, kernel_type, kernel_data, kernel_step, kernel_width, kernel_height, anchor_x, anchor_y, - borderType, borderValue, iterations, isSubmatrix)); + borderType, borderValue, iterations, isSubmatrix));*/ ocvMorph(op, src_type, dst_type, src_data, src_step, dst_data, dst_step, width, height, roi_width, roi_height, roi_x, roi_y, @@ -1079,7 +1079,7 @@ static bool ocl_morphologyEx(InputArray _src, OutputArray _dst, int op, #endif #define IPP_DISABLE_MORPH_ADV 1 -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP #if !IPP_DISABLE_MORPH_ADV static bool ipp_morphologyEx(int op, InputArray _src, OutputArray _dst, InputArray _kernel, @@ -1174,7 +1174,7 @@ void morphologyEx( InputArray _src, OutputArray _dst, int op, Mat dst = _dst.getMat(); #if !IPP_DISABLE_MORPH_ADV - CV_IPP_RUN_FAST(ipp_morphologyEx(op, src, dst, kernel, anchor, iterations, borderType, borderValue)); + //CV_IPP_RUN_FAST(ipp_morphologyEx(op, src, dst, kernel, anchor, iterations, borderType, borderValue)); #endif switch( op ) diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp index 4e514eb8b8..abae02b525 100644 --- a/modules/imgproc/src/smooth.dispatch.cpp +++ b/modules/imgproc/src/smooth.dispatch.cpp @@ -363,7 +363,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, #endif -#ifdef HAVE_IPP +#if 0 //defined HAVE_IPP // IW 2017u2 has bug which doesn't allow use of partial inMem with tiling #if IPP_DISABLE_GAUSSIANBLUR_PARALLEL #define IPP_GAUSSIANBLUR_PARALLEL 0 @@ -533,7 +533,7 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, CV_OVX_RUN(true, openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType)) - CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType)); + //CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType)); if(sdepth == CV_8U && ((borderType & BORDER_ISOLATED) || !_src.getMat().isSubmatrix())) { From 03fe1cb7fc4edba47749a5bc77dc60c5d2eb775b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Thu, 1 Aug 2019 15:28:04 +0200 Subject: [PATCH 13/23] Support building shared libraries on WINCE. --- cmake/templates/dllmain.cpp.in | 10 ++++++++-- modules/core/src/glob.cpp | 4 ++-- modules/core/src/utils/datafile.cpp | 15 +++++++++++---- .../wince/arm-wince-headless-overrides.cmake | 4 ++-- platforms/wince/readme.md | 8 ++++++++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/cmake/templates/dllmain.cpp.in b/cmake/templates/dllmain.cpp.in index 6b3005f654..db95f5d00c 100644 --- a/cmake/templates/dllmain.cpp.in +++ b/cmake/templates/dllmain.cpp.in @@ -18,11 +18,17 @@ namespace cv { extern __declspec(dllimport) bool __termination; // Details: #12750 } +#ifdef _WIN32_WCE +#define DLL_MAIN_ARG0 HANDLE +#else +#define DLL_MAIN_ARG0 HINSTANCE +#endif + extern "C" -BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved); +BOOL WINAPI DllMain(DLL_MAIN_ARG0, DWORD fdwReason, LPVOID lpReserved); extern "C" -BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved) +BOOL WINAPI DllMain(DLL_MAIN_ARG0, DWORD fdwReason, LPVOID lpReserved) { if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH) { diff --git a/modules/core/src/glob.cpp b/modules/core/src/glob.cpp index db054daa52..fa8592caa5 100644 --- a/modules/core/src/glob.cpp +++ b/modules/core/src/glob.cpp @@ -139,7 +139,7 @@ const char dir_separators[] = "/"; static bool isDir(const cv::String& path, DIR* dir) { -#if defined _WIN32 || defined WINCE +#if defined _WIN32 || defined _WIN32_WCE DWORD attributes; BOOL status = TRUE; if (dir) @@ -147,7 +147,7 @@ static bool isDir(const cv::String& path, DIR* dir) else { WIN32_FILE_ATTRIBUTE_DATA all_attrs; -#ifdef WINRT +#if defined WINRT || defined _WIN32_WCE wchar_t wpath[MAX_PATH]; size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH); CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp index f1107b097a..257d27b738 100644 --- a/modules/core/src/utils/datafile.cpp +++ b/modules/core/src/utils/datafile.cpp @@ -115,13 +115,20 @@ static cv::String getModuleLocation(const void* addr) #endif if (m) { - char path[MAX_PATH]; - const size_t path_size = sizeof(path)/sizeof(*path); - size_t sz = GetModuleFileNameA(m, path, path_size); // no unicode support + TCHAR path[MAX_PATH]; + const size_t path_size = sizeof(path) / sizeof(*path); + size_t sz = GetModuleFileName(m, path, path_size); if (sz > 0 && sz < path_size) { - path[sz] = '\0'; + path[sz] = TCHAR('\0'); +#ifdef _UNICODE + char char_path[MAX_PATH]; + size_t copied = wcstombs(char_path, path, MAX_PATH); + CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); + return cv::String(char_path); +#else return cv::String(path); +#endif } } #elif defined(__linux__) diff --git a/platforms/wince/arm-wince-headless-overrides.cmake b/platforms/wince/arm-wince-headless-overrides.cmake index e658f8812e..e31530c535 100644 --- a/platforms/wince/arm-wince-headless-overrides.cmake +++ b/platforms/wince/arm-wince-headless-overrides.cmake @@ -3,10 +3,10 @@ if(WINCE) # Try_Compile succeed and therefore also C/C++ ABI Detetection work # https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Windows- # MSVC.cmake - set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib oldnames.lib") set(CMAKE_CXX_STANDARD_LIBRARIES_INIT ${CMAKE_C_STANDARD_LIBRARIES_INIT}) foreach(ID EXE SHARED MODULE) string(APPEND CMAKE_${ID}_LINKER_FLAGS_INIT - " /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib") + " /NODEFAULTLIB:libc.lib") endforeach() endif() diff --git a/platforms/wince/readme.md b/platforms/wince/readme.md index 3b7ca2c764..652087368d 100644 --- a/platforms/wince/readme.md +++ b/platforms/wince/readme.md @@ -57,6 +57,14 @@ For headless WEC2013, this configuration may not be limited to but is known to w -DWITH_TIFF=OFF ` ``` +## Configuring to build as shared +Building OpenCV as shared libraries is as easy as appending +``` +-DBUILD_SHARED_LIBS=ON ` +-DBUILD_ZLIB=ON +``` +to the build configuration. + ## Building You are required to build using Unicode: `cmake --build . -- /p:CharacterSet=Unicode` From b231e91d87fd7b16e18ac9fdfe8b2466d7d48ee4 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 26 Jul 2019 15:37:28 +0300 Subject: [PATCH 14/23] Fix for building with old V4L --- modules/videoio/src/cap_v4l.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 2e279464f8..8035d456b5 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -258,6 +258,10 @@ make & enjoy! #define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17) #endif +#ifndef V4L2_PIX_FMT_Y10 +#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') +#endif + /* Defaults - If your board can do better, set it here. Set for the most common type inputs. */ #define DEFAULT_V4L_WIDTH 640 #define DEFAULT_V4L_HEIGHT 480 From 63775320ae02a68a5c8fd7a930253fb08d2d9367 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 4 Aug 2019 18:24:33 -0400 Subject: [PATCH 15/23] Verify Carbon correctly on OSX --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43b0060938..bc90983453 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,8 +240,8 @@ OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON VISIBLE_IF APPLE VERIFY HAVE_AVFOUNDATION) OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa (OBSOLETE)" OFF - VISIBLE_IF APPLE - VERIFY HAVE_CARBON OR HAVE_COCOA) + VISIBLE_IF (APPLE OR HAVE_COCOA) + VERIFY HAVE_CARBON) OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON VISIBLE_IF (ARM OR AARCH64) AND NOT IOS AND NOT (CMAKE_VERSION VERSION_LESS "2.8.11")) OCV_OPTION(WITH_CPUFEATURES "Use cpufeatures Android library" ON From d6ba235655bfef9b63c195381303547fb24dc583 Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Mon, 5 Aug 2019 17:42:48 +0900 Subject: [PATCH 16/23] fix fall through warning --- 3rdparty/carotene/hal/tegra_hal.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/3rdparty/carotene/hal/tegra_hal.hpp b/3rdparty/carotene/hal/tegra_hal.hpp index b91f862d1a..2dfa30b619 100644 --- a/3rdparty/carotene/hal/tegra_hal.hpp +++ b/3rdparty/carotene/hal/tegra_hal.hpp @@ -1127,6 +1127,7 @@ inline int TEGRA_FILTERINIT(cvhalFilter2D **context, uchar *kernel_data, size_t { std::memcpy(ctx->kernel_data + kernel_width * j, kernel_data + kernel_step * j, kernel_width * sizeof(int16_t)); } + break; default: delete[] ctx->kernel_data; delete ctx; @@ -1243,6 +1244,7 @@ inline int TEGRA_SEPFILTERINIT(cvhalFilter2D **context, int src_type, int dst_ty ctx->kernely_data[0]=((int16_t*)kernely_data)[0]; ctx->kernely_data[1]=((int16_t*)kernely_data)[1]; ctx->kernely_data[2]=((int16_t*)kernely_data)[2]; + break; default: delete ctx; return CV_HAL_ERROR_NOT_IMPLEMENTED; From cadb4dee145fcb467c6cf297a725ded72725d3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yaohai=20=5B=E5=A7=9A=E6=B5=B7=5D?= Date: Mon, 5 Aug 2019 17:11:46 +0800 Subject: [PATCH 17/23] fix exif bug --- modules/imgcodecs/src/exif.cpp | 4 ++-- modules/imgcodecs/src/exif.hpp | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/imgcodecs/src/exif.cpp b/modules/imgcodecs/src/exif.cpp index a556dd0e3c..051999c0fa 100644 --- a/modules/imgcodecs/src/exif.cpp +++ b/modules/imgcodecs/src/exif.cpp @@ -229,7 +229,7 @@ void ExifReader::parseExif() uint32_t offset = getStartOffset(); - size_t numEntry = getNumDirEntry(); + size_t numEntry = getNumDirEntry( offset ); offset += 2; //go to start of tag fields @@ -303,7 +303,7 @@ uint32_t ExifReader::getStartOffset() const * * @return The number of directory entries */ -size_t ExifReader::getNumDirEntry() const +size_t ExifReader::getNumDirEntry(const size_t offsetNumDir) const { return getU16( offsetNumDir ); } diff --git a/modules/imgcodecs/src/exif.hpp b/modules/imgcodecs/src/exif.hpp index bbc92e813e..f7f4e383e9 100644 --- a/modules/imgcodecs/src/exif.hpp +++ b/modules/imgcodecs/src/exif.hpp @@ -199,7 +199,7 @@ private: bool checkTagMark() const; size_t getFieldSize (); - size_t getNumDirEntry() const; + size_t getNumDirEntry( const size_t offsetNumDir ) const; uint32_t getStartOffset() const; uint16_t getExifTag( const size_t offset ) const; uint16_t getU16( const size_t offset ) const; @@ -225,9 +225,6 @@ private: private: static const uint16_t tagMarkRequired = 0x2A; - //offset to the _number-of-directory-entry_ field - static const size_t offsetNumDir = 8; - //max size of data in tag. //'DDDDDDDD' contains the value of that Tag. If its size is over 4bytes, //'DDDDDDDD' contains the offset to data stored address. From 406313bbc53ef2618abd462a2cbe736013fed067 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 5 Aug 2019 16:57:04 +0300 Subject: [PATCH 18/23] videoio(test): skip unstable MSMF tests --- modules/videoio/test/test_video_io.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/videoio/test/test_video_io.cpp b/modules/videoio/test/test_video_io.cpp index 0ac93c7f24..a660058680 100644 --- a/modules/videoio/test/test_video_io.cpp +++ b/modules/videoio/test/test_video_io.cpp @@ -168,6 +168,8 @@ public: { if (!isBackendAvailable(apiPref, cv::videoio_registry::getStreamBackends())) throw SkipTestException(cv::String("Backend is not available/disabled: ") + cv::videoio_registry::getBackendName(apiPref)); + if (cvtest::skipUnstableTests && apiPref == CAP_MSMF && (ext == "h264" || ext == "h265")) + throw SkipTestException("Unstable MSMF test"); VideoCapture cap; EXPECT_NO_THROW(cap.open(video_file, apiPref)); if (!cap.isOpened()) From b9d6fc9dad33895ab3566f0eda1d33624860803d Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 19 Jul 2019 14:07:09 +0200 Subject: [PATCH 19/23] Fix cv::selectROI rectangle rendering issue backport of commit: 95c65aff75f62407ca1e99bbfa18e2d54322aab5 --- modules/highgui/src/roiSelector.cpp | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/highgui/src/roiSelector.cpp b/modules/highgui/src/roiSelector.cpp index d8ca58047e..4fba07eacb 100644 --- a/modules/highgui/src/roiSelector.cpp +++ b/modules/highgui/src/roiSelector.cpp @@ -106,10 +106,10 @@ class ROISelector bool isDrawing; Rect2d box; Mat image; + Point2f startPos; // parameters for drawing from the center bool drawFromCenter; - Point2f center; // initializer list handlerT() : isDrawing(false), drawFromCenter(true){}; @@ -136,19 +136,31 @@ class ROISelector { if (selectorParams.drawFromCenter) { - selectorParams.box.width = 2 * (x - selectorParams.center.x); - selectorParams.box.height = 2 * (y - selectorParams.center.y); - selectorParams.box.x = std::min( - std::max(selectorParams.center.x - selectorParams.box.width / 2.0, 0.), (double)imageSize.width); - selectorParams.box.y = std::min( - std::max(selectorParams.center.y - selectorParams.box.height / 2.0, 0.), (double)imageSize.height); + // limit half extends to imageSize + float halfWidth = std::min(std::min( + std::abs(x - selectorParams.startPos.x), + selectorParams.startPos.x), + imageSize.width - selectorParams.startPos.x); + float halfHeight = std::min(std::min( + std::abs(y - selectorParams.startPos.y), + selectorParams.startPos.y), + imageSize.height - selectorParams.startPos.y); + + selectorParams.box.width = halfWidth * 2; + selectorParams.box.height = halfHeight * 2; + selectorParams.box.x = selectorParams.startPos.x - halfWidth; + selectorParams.box.y = selectorParams.startPos.y - halfHeight; + } else { - selectorParams.box.width = std::max( - std::min(x - selectorParams.box.x, (double)imageSize.width - selectorParams.box.x), - selectorParams.box.x); - selectorParams.box.height = std::max( - std::min(y - selectorParams.box.y, (double)imageSize.height - selectorParams.box.y), - selectorParams.box.y); + // limit x and y to imageSize + int lx = std::min(std::max(x, 0), imageSize.width); + int by = std::min(std::max(y, 0), imageSize.height); + selectorParams.box.width = std::abs(lx - selectorParams.startPos.x); + selectorParams.box.height = std::abs(by - selectorParams.startPos.y); + selectorParams.box.x = std::min((float)lx, selectorParams.startPos.x); + selectorParams.box.y = std::min((float)by, selectorParams.startPos.y); } } break; @@ -157,7 +169,7 @@ class ROISelector case EVENT_LBUTTONDOWN: selectorParams.isDrawing = true; selectorParams.box = Rect2d(x, y, 0, 0); - selectorParams.center = Point2f((float)x, (float)y); + selectorParams.startPos = Point2f((float)x, (float)y); break; // cleaning up the selected bounding box From 960bb540ecdd8a2feed3cb06f305d8f315652c09 Mon Sep 17 00:00:00 2001 From: TheGoddessInari Date: Sun, 28 Jul 2019 10:21:15 -0700 Subject: [PATCH 20/23] Make sure to use defined(__GNUC__) instead of bare __GNUC__ in flann2 header. This fixes a compiler error on MSVC with Unreal Engine (at least). backport of commit: 4e998c9adeb8ec874d29a0ed5d450da3a9bdd0e8 --- modules/flann/include/opencv2/flann/dist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 0670122c16..4246a3dffc 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -441,7 +441,7 @@ struct Hamming result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0); result += vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),2); } -#elif __GNUC__ +#elif defined(__GNUC__) { //for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll) typedef unsigned long long pop_t; From 987bb2ca617eaab61a99da28273f513aef37665d Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Sat, 3 Aug 2019 12:53:38 -0700 Subject: [PATCH 21/23] Fix build for UWP backport of commit: f18cbd036af7b22017f5f964be6f398ccb0c1a57 --- cmake/OpenCVModule.cmake | 2 +- modules/core/src/utils/datafile.cpp | 2 +- modules/videoio/src/cap_ffmpeg.cpp | 2 +- modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index c2fda8fad6..3f7dfdc6d6 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -850,7 +850,7 @@ macro(ocv_create_module) set(the_module_target ${the_module}) endif() - if(WINRT) + if(WINRT AND BUILD_TESTS) # removing APPCONTAINER from modules to run from console # in case of usual starting of WinRT test apps output is missing # so starting of console version w/o APPCONTAINER is required to get test results diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp index 257d27b738..088ad1ce79 100644 --- a/modules/core/src/utils/datafile.cpp +++ b/modules/core/src/utils/datafile.cpp @@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr) CV_UNUSED(addr); #ifdef _WIN32 HMODULE m = 0; -#if _WIN32_WINNT >= 0x0501 +#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(addr), &m); diff --git a/modules/videoio/src/cap_ffmpeg.cpp b/modules/videoio/src/cap_ffmpeg.cpp index df7e44647b..67ee2e636d 100644 --- a/modules/videoio/src/cap_ffmpeg.cpp +++ b/modules/videoio/src/cap_ffmpeg.cpp @@ -80,7 +80,7 @@ static cv::Mutex _icvInitFFMPEG_mutex; static const HMODULE cv_GetCurrentModule() { HMODULE h = 0; -#if _WIN32_WINNT >= 0x0501 +#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(cv_GetCurrentModule), &h); diff --git a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp index 236e22766e..eccf97e979 100644 --- a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp +++ b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp @@ -94,7 +94,7 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber() void Media::CaptureFrameGrabber::ShowCameraSettings() { -#if WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PC_APP) if (_state == State::Started) { CameraOptionsUI::Show(_capture.Get()); From ca79f75b321c0641a17e5136e4dfa8d3022372e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Gurin?= Date: Mon, 5 Aug 2019 09:41:59 -0300 Subject: [PATCH 22/23] OpenCV.js docker container build instructions backport of commit: 59b0314a0ef49d407f78742fc44fdc19bd20bf0e --- .../js_setup/js_setup/js_setup.markdown | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/js_tutorials/js_setup/js_setup/js_setup.markdown b/doc/js_tutorials/js_setup/js_setup/js_setup.markdown index 5f6b43b167..5036fd1d97 100644 --- a/doc/js_tutorials/js_setup/js_setup/js_setup.markdown +++ b/doc/js_tutorials/js_setup/js_setup/js_setup.markdown @@ -7,6 +7,9 @@ Installing Emscripten [Emscripten](https://github.com/kripken/emscripten) is an LLVM-to-JavaScript compiler. We will use Emscripten to build OpenCV.js. +@note +While this describes installation of required tools from scratch, there's a section below also describing an alternative procedure to perform the same build using docker containers which is often easier. + To Install Emscripten, follow instructions of [Emscripten SDK](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). For example: @@ -103,3 +106,25 @@ Building OpenCV.js from Source @note It requires `node` installed in your development environment. + +Building OpenCV.js with Docker +--------------------------------------- + +Alternatively, the same build can be can be accomplished using [docker](https://www.docker.com/) containers which is often easier and more reliable, particularly in non linux systems. You only need to install [docker](https://www.docker.com/) on your system and use a popular container that provides a clean well tested environment for emscripten builds like this, that already has latest versions of all the necessary tools installed. + +So, make sure [docker](https://www.docker.com/) is installed in your system and running. The following shell script should work in linux and MacOS: + +@code{.bash} +git clone https://github.com/opencv/opencv.git +cd opencv +docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:latest" python ./platforms/js/build_js.py build_js +@endcode + +In Windows use the following PowerShell command: + +@code{.bash} +docker run --rm --workdir /code -v "$(get-location):/code" "trzeci/emscripten:latest" python ./platforms/js/build_js.py build_js +@endcode + +@note +The example uses latest version of [trzeci/emscripten](https://hub.docker.com/r/trzeci/emscripten) docker container. At this time, the latest version works fine and is `trzeci/emscripten:sdk-tag-1.38.32-64bit` From a4b4432015113dfb81259d09a2ccd7c180fbe101 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 5 Aug 2019 19:13:17 +0300 Subject: [PATCH 23/23] videoio(test): skip unstable MSMF tests (2) --- modules/videoio/test/test_video_io.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/videoio/test/test_video_io.cpp b/modules/videoio/test/test_video_io.cpp index a660058680..ce4523ac33 100644 --- a/modules/videoio/test/test_video_io.cpp +++ b/modules/videoio/test/test_video_io.cpp @@ -83,6 +83,8 @@ public: { if (!isBackendAvailable(apiPref, cv::videoio_registry::getStreamBackends())) throw SkipTestException(cv::String("Backend is not available/disabled: ") + cv::videoio_registry::getBackendName(apiPref)); + if (cvtest::skipUnstableTests && apiPref == CAP_MSMF && (ext == "h264" || ext == "h265")) + throw SkipTestException("Unstable MSMF test"); VideoCapture cap; ASSERT_NO_THROW(cap.open(video_file, apiPref)); if (!cap.isOpened())