From 3d1dbd2ccd7b8fddf189c5ebf72c842268eaa3b7 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sun, 3 Mar 2019 21:43:27 +0300 Subject: [PATCH 01/16] clean up C API --- modules/imgproc/test/test_canny.cpp | 7 -- modules/imgproc/test/test_drawing.cpp | 171 -------------------------- modules/imgproc/test/test_filter.cpp | 11 +- 3 files changed, 5 insertions(+), 184 deletions(-) diff --git a/modules/imgproc/test/test_canny.cpp b/modules/imgproc/test/test_canny.cpp index 161b839f4883..f4d277a3865d 100644 --- a/modules/imgproc/test/test_canny.cpp +++ b/modules/imgproc/test/test_canny.cpp @@ -75,8 +75,6 @@ CV_CannyTest::CV_CannyTest(bool custom_deriv) aperture_size = 0; use_true_gradient = false; threshold1 = threshold2 = 0; - - test_cpp = false; test_custom_deriv = custom_deriv; const char imgPath[] = "shared/fruits.png"; @@ -158,11 +156,6 @@ void CV_CannyTest::run_func() cvtest::filter2D(src, dy, CV_16S, dykernel, anchor, 0, BORDER_REPLICATE); cv::Canny(dx, dy, _out, threshold1, threshold2, use_true_gradient); } - else if(!test_cpp) - { - cvCanny( test_array[INPUT][0], test_array[OUTPUT][0], threshold1, threshold2, - aperture_size + (use_true_gradient ? CV_CANNY_L2_GRADIENT : 0)); - } else { cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]); diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index c42d7aa572ba..f18709448c39 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -245,176 +245,6 @@ int CV_DrawingTest_CPP::checkLineIterator( Mat& img ) return 0; } -class CV_DrawingTest_C : public CV_DrawingTest -{ -public: - CV_DrawingTest_C() {} -protected: - virtual void draw( Mat& img ); - virtual int checkLineIterator( Mat& img); -}; - -void CV_DrawingTest_C::draw( Mat& _img ) -{ - CvSize imgSize = cvSize(600, 400); - _img.create( imgSize, CV_8UC3 ); - CvMat img = cvMat(_img); - - vector polyline(4); - polyline[0] = cvPoint(0, 0); - polyline[1] = cvPoint(imgSize.width, 0); - polyline[2] = cvPoint(imgSize.width, imgSize.height); - polyline[3] = cvPoint(0, imgSize.height); - CvPoint* pts = &polyline[0]; - int n = (int)polyline.size(); - int actualSize = 0; - cvFillPoly( &img, &pts, &n, 1, cvScalar(255,255,255) ); - - CvPoint p1 = cvPoint(1,1), p2 = cvPoint(3,3); - if( cvClipLine(imgSize, &p1, &p2) ) - cvCircle( &img, cvPoint(300,100), 40, cvScalar(0,0,255), 3 ); // draw - - p1 = cvPoint(1,1), p2 = cvPoint(3,imgSize.height+1000); - if( cvClipLine(imgSize, &p1, &p2) ) - cvCircle( &img, cvPoint(500,300), 50, cvScalar(255,0,0), 5, 8, 1 ); // draw - - p1 = cvPoint(imgSize.width,1), p2 = cvPoint(imgSize.width,3); - if( cvClipLine(imgSize, &p1, &p2) ) - cvCircle( &img, cvPoint(390,100), 10, cvScalar(0,0,255), 3 ); // not draw - - p1 = cvPoint(imgSize.width-1,1), p2 = cvPoint(imgSize.width,3); - if( cvClipLine(imgSize, &p1, &p2) ) - cvEllipse( &img, cvPoint(390,100), cvSize(20,30), 60, 0, 220.0, cvScalar(0,200,0), 4 ); //draw - - CvBox2D box; - box.center.x = 100; - box.center.y = 200; - box.size.width = 200; - box.size.height = 100; - box.angle = 160; - cvEllipseBox( &img, box, cvScalar(200,200,255), 5 ); - - polyline.resize(9); - pts = &polyline[0]; - n = (int)polyline.size(); - actualSize = cvEllipse2Poly( cvPoint(430,180), cvSize(100,150), 30, 0, 150, &polyline[0], 20 ); - CV_Assert(actualSize == n); - cvPolyLine( &img, &pts, &n, 1, false, cvScalar(0,0,150), 4, CV_AA ); - n = 0; - for( vector::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ ) - { - cvLine( &img, *it, *(it+1), cvScalar(50,250,100) ); - } - - polyline.resize(19); - pts = &polyline[0]; - n = (int)polyline.size(); - actualSize = cvEllipse2Poly( cvPoint(500,300), cvSize(50,80), 0, 0, 180, &polyline[0], 10 ); - CV_Assert(actualSize == n); - cvPolyLine( &img, &pts, &n, 1, true, cvScalar(100,200,100), 20 ); - cvFillConvexPoly( &img, pts, n, cvScalar(0, 80, 0) ); - - polyline.resize(8); - // external rectengular - polyline[0] = cvPoint(500, 20); - polyline[1] = cvPoint(580, 20); - polyline[2] = cvPoint(580, 100); - polyline[3] = cvPoint(500, 100); - // internal rectangular - polyline[4] = cvPoint(520, 40); - polyline[5] = cvPoint(560, 40); - polyline[6] = cvPoint(560, 80); - polyline[7] = cvPoint(520, 80); - CvPoint* ppts[] = {&polyline[0], &polyline[0]+4}; - int pn[] = {4, 4}; - cvFillPoly( &img, ppts, pn, 2, cvScalar(100, 100, 0), 8, 0 ); - - cvRectangle( &img, cvPoint(0, 300), cvPoint(50, 398), cvScalar(0,0,255) ); - - string text1 = "OpenCV"; - CvFont font; - cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 2, 2, 0, 3 ); - int baseline = 0; - CvSize textSize = {0, 0}; - cvGetTextSize( text1.c_str(), &font, &textSize, &baseline ); - baseline += font.thickness; - CvPoint textOrg = cvPoint((imgSize.width - textSize.width)/2, (imgSize.height + textSize.height)/2); - cvRectangle( &img, cvPoint( textOrg.x, textOrg.y + baseline), - cvPoint(textOrg.x + textSize.width, textOrg.y - textSize.height), cvScalar(0,0,255)); - cvLine( &img, cvPoint(textOrg.x, textOrg.y + font.thickness), - cvPoint(textOrg.x + textSize.width, textOrg.y + font.thickness), cvScalar(0, 0, 255)); - cvPutText( &img, text1.c_str(), textOrg, &font, cvScalar(150,0,150) ); - - int dist = 5; - string text2 = "abcdefghijklmnopqrstuvwxyz1234567890"; - CvScalar color = cvScalar(200,0,0); - cvInitFont( &font, FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(5, 5+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_TRIPLEX, 0.5, 0.5, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_COMPLEX_SMALL, 1, 1, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist + 180); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 1, 1, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - cvInitFont( &font, FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); - - dist = 15; - cvInitFont( &font, FONT_ITALIC, 0.5, 0.5, 0, 1, CV_AA ); - cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); - textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); - cvPutText(&img, text2.c_str(), textOrg, &font, color ); -} - -int CV_DrawingTest_C::checkLineIterator( Mat& _img ) -{ - CvLineIterator it; - CvMat img = cvMat(_img); - int count = cvInitLineIterator( &img, cvPoint(0,300), cvPoint(1000, 300), &it ); - for(int i = 0; i < count; i++ ) - { - Vec3b v = (Vec3b)(*(it.ptr)) - _img.at(300,i); - float err = (float)cvtest::norm( v, NORM_L2 ); - if( err != 0 ) - { - ts->printf( ts->LOG, "CvLineIterator works incorrect" ); - ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); - } - CV_NEXT_LINE_POINT(it); - } - ts->set_failed_test_info(cvtest::TS::OK); - return 0; -} - class CV_DrawingTest_Far : public CV_DrawingTest_CPP { public: @@ -549,7 +379,6 @@ void CV_DrawingTest_Far::draw(Mat& img) } TEST(Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); } -TEST(Drawing, c_regression) { CV_DrawingTest_C test; test.safe_run(); } TEST(Drawing, far_regression) { CV_DrawingTest_Far test; test.safe_run(); } class CV_FillConvexPolyTest : public cvtest::BaseTest diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index 5b73e3bf8ea9..8cc7d05546b1 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -536,11 +536,9 @@ void CV_SobelTest::get_test_array_types_and_sizes( int test_case_idx, void CV_SobelTest::run_func() { - cvSobel( test_array[inplace ? OUTPUT : INPUT][0], - test_array[OUTPUT][0], dx, dy, _aperture_size ); - /*cv::Sobel( test_mat[inplace ? OUTPUT : INPUT][0], + cv::Sobel( test_mat[inplace ? OUTPUT : INPUT][0], test_mat[OUTPUT][0], test_mat[OUTPUT][0].depth(), - dx, dy, _aperture_size, 1, 0, border );*/ + dx, dy, _aperture_size, 1, 0, border ); } @@ -655,8 +653,9 @@ void CV_LaplaceTest::get_test_array_types_and_sizes( int test_case_idx, void CV_LaplaceTest::run_func() { - cvLaplace( test_array[inplace ? OUTPUT : INPUT][0], - test_array[OUTPUT][0], _aperture_size ); + cv::Laplacian( test_mat[inplace ? OUTPUT : INPUT][0], + test_mat[OUTPUT][0],test_mat[OUTPUT][0].depth(), + _aperture_size, 1, 0, cv::BORDER_REPLICATE ); } From 9515137cb2d880718a76df76d5a39df32e693a5c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 12 Apr 2019 17:24:08 +0300 Subject: [PATCH 02/16] cmake: fix PCH generation process defines from INTERFACE targets --- cmake/OpenCVPCHSupport.cmake | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake index 59bc826ed056..059079340117 100644 --- a/cmake/OpenCVPCHSupport.cmake +++ b/cmake/OpenCVPCHSupport.cmake @@ -43,18 +43,9 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags) LIST(APPEND ${_out_compile_flags} "-fPIC") ENDIF() - GET_PROPERTY(_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS) - if(_definitions) - foreach(_def ${_definitions}) - LIST(APPEND ${_out_compile_flags} "\"-D${_def}\"") - endforeach() - endif() - GET_TARGET_PROPERTY(_target_definitions ${_PCH_current_target} COMPILE_DEFINITIONS) - if(_target_definitions) - foreach(_def ${_target_definitions}) - LIST(APPEND ${_out_compile_flags} "\"-D${_def}\"") - endforeach() - endif() + # Processed via $ + #GET_PROPERTY(_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS) + #GET_TARGET_PROPERTY(_target_definitions ${_PCH_current_target} COMPILE_DEFINITIONS) GET_TARGET_PROPERTY(_cxx_standard ${_PCH_current_target} CXX_STANDARD) if (_cxx_standard) @@ -304,12 +295,22 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _input) #message("_command ${_input} ${_output}") _PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output} ) + set(_pch_generate_file_cmd "${CMAKE_CURRENT_BINARY_DIR}/${_name}.command.sh") + string(REPLACE " " "\\ " _command "${_command}") + string(REPLACE ";" " " _command "${_command}") + file(GENERATE OUTPUT "${_pch_generate_file_cmd}" CONTENT "#!/bin/sh +if [ -n \"$VERBOSE\" ]; then + tail -n1 \$0 +fi +${_command} -D$, -D> +") GET_FILENAME_COMPONENT(_outdir ${_output} PATH) ADD_CUSTOM_COMMAND( OUTPUT "${_output}" COMMAND ${CMAKE_COMMAND} -E make_directory "${_outdir}" - COMMAND ${_command} - DEPENDS "${_input}" + COMMAND chmod +x "${_pch_generate_file_cmd}" + COMMAND "${_pch_generate_file_cmd}" + DEPENDS "${_input}" "${_pch_generate_file_cmd}" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_name}" DEPENDS ${_targetName}_pch_dephelp ) From 0cfd95c097feead5f8f045b2170021eceadebdd7 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Fri, 12 Apr 2019 18:40:27 +0300 Subject: [PATCH 03/16] Fix TensorFlow's Squeeze and a new fusion for SoftMax from slim backend --- modules/dnn/src/layers/flatten_layer.cpp | 10 ++++ .../src/tensorflow/tf_graph_simplifier.cpp | 25 ++++++++++ modules/dnn/src/tensorflow/tf_importer.cpp | 21 +++++--- modules/dnn/test/test_tf_importer.cpp | 49 +++++++++++++++++++ 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/modules/dnn/src/layers/flatten_layer.cpp b/modules/dnn/src/layers/flatten_layer.cpp index 3a704dca812e..8672ea3e4f0c 100644 --- a/modules/dnn/src/layers/flatten_layer.cpp +++ b/modules/dnn/src/layers/flatten_layer.cpp @@ -105,6 +105,16 @@ class FlattenLayerImpl CV_FINAL : public FlattenLayer return true; } + void finalize(InputArrayOfArrays inputs_arr, OutputArrayOfArrays) CV_OVERRIDE + { + std::vector inputs; + inputs_arr.getMatVector(inputs); + + int numAxes = inputs[0].dims; + _startAxis = clamp(_startAxis, numAxes); + _endAxis = clamp(_endAxis, numAxes); + } + #ifdef HAVE_OPENCL bool forward_ocl(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) { diff --git a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp index 37e57505da7b..7f1001888a4c 100644 --- a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp +++ b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp @@ -646,6 +646,30 @@ class SoftMaxSlimSubgraph : public Subgraph } }; +class SoftMaxSlimV2Subgraph : public Subgraph +{ +public: + SoftMaxSlimV2Subgraph() + { + int input = addNodeToMatch(""); + int shape = addNodeToMatch("Shape", input); + int shape_2 = addNodeToMatch("Shape", input); + int rank = addNodeToMatch("Const"); + int y = addNodeToMatch("Const"); + int sub = addNodeToMatch("Sub", rank, y); + int begin = addNodeToMatch("Pack", sub); + int size = addNodeToMatch("Const"); + int slice = addNodeToMatch("Slice", shape, begin, size); + int values = addNodeToMatch("Const"); + int axis = addNodeToMatch("Const"); + int concat = addNodeToMatch("ConcatV2", values, slice, axis); + int reshape = addNodeToMatch("Reshape", input, concat); + int softmax = addNodeToMatch("Softmax", reshape); + addNodeToMatch("Reshape", softmax, shape_2); + setFusedNode("Softmax", input); + } +}; + void simplifySubgraphs(tensorflow::GraphDef& net) { std::vector > subgraphs; @@ -663,6 +687,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net) subgraphs.push_back(Ptr(new UpsamplingKerasSubgraph())); subgraphs.push_back(Ptr(new ReshapeAsShapeSubgraph())); subgraphs.push_back(Ptr(new SoftMaxSlimSubgraph())); + subgraphs.push_back(Ptr(new SoftMaxSlimV2Subgraph())); int numNodes = net.node_size(); std::vector matchedNodesIds; diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index a1628104f710..15aecba0958a 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -1125,18 +1125,25 @@ void TFImporter::populateNet(Net dstNet) { CV_Assert(hasLayerAttr(layer, "squeeze_dims")); const tensorflow::AttrValue& dims = getLayerAttr(layer, "squeeze_dims"); - if (inpLayout == DATA_LAYOUT_NHWC) + std::vector dimsVector(dims.list().i_size()); + for (int i = 0; i < dimsVector.size(); ++i) + dimsVector[i] = dims.list().i(i); + + // Flatten layer can squeeze dimensions range into one. + std::sort(dimsVector.begin(), dimsVector.end()); + for (int i = 1; i < dimsVector.size(); ++i) { - if (dims.list().i_size() != 2 || dims.list().i(0) != 1 || dims.list().i(1) != 2) + if (dimsVector[i] != dimsVector[i - 1] + 1) CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration"); } - else if (inpLayout == DATA_LAYOUT_NCHW) + int start = dimsVector.front() - 1, end = dimsVector.back(); + if (start == -1 && end == 0) // squeeze 0th dimension { - if (dims.list().i_size() != 2 || dims.list().i(0) != 2 || dims.list().i(1) != 3) - CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration"); + start = 0; + end = 1; } - else - CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration"); + layerParams.set("axis", start); + layerParams.set("end_axis", end); } if (inpLayout == DATA_LAYOUT_NHWC) { diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index 05f82725e965..1c4b96a6ecf4 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -658,6 +658,17 @@ TEST_P(Test_TensorFlow_layers, softmax) runTensorFlowNet("slim_softmax"); } +TEST_P(Test_TensorFlow_layers, slim_softmax_v2) +{ +#if defined(INF_ENGINE_RELEASE) + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD && + getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2 + ) + throw SkipTestException("Test is disabled for Myriad2"); +#endif + runTensorFlowNet("slim_softmax_v2"); +} + TEST_P(Test_TensorFlow_layers, relu6) { runTensorFlowNet("keras_relu6"); @@ -675,6 +686,44 @@ TEST_P(Test_TensorFlow_layers, resize_bilinear) runTensorFlowNet("resize_bilinear_factor"); } +TEST_P(Test_TensorFlow_layers, squeeze) +{ +#if defined(INF_ENGINE_RELEASE) + if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD + && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2 + ) + throw SkipTestException("Test is disabled for Myriad2"); +#endif + int inpShapes[][4] = {{1, 3, 4, 2}, {1, 3, 1, 2}, {1, 3, 4, 1}, {1, 3, 4, 1}}; // TensorFlow's shape (NHWC) + int outShapes[][3] = {{3, 4, 2}, {1, 3, 2}, {1, 3, 4}, {1, 3, 4}}; + int squeeze_dims[] = {0, 2, 3, -1}; + for (int i = 0; i < 4; ++i) + { + SCOPED_TRACE(format("i=%d", i)); + std::string pbtxt = + "node { name: \"input\" op: \"Placeholder\"" + "attr { key: \"data_format\" value { s: \"NHWC\" } } }" + "node { name: \"squeeze\" op: \"Squeeze\" input: \"input\"" + "attr { key: \"squeeze_dims\" value { list { i:" + format("%d", squeeze_dims[i]) + "}}}}"; + Net net = readNetFromTensorflow(0, 0, pbtxt.c_str(), pbtxt.size()); + net.setPreferableBackend(backend); + net.setPreferableTarget(target); + Mat tfInp(4, &inpShapes[i][0], CV_32F); + randu(tfInp, -1, 1); + + // NHWC to NCHW + CV_Assert(inpShapes[i][0] == 1); + std::swap(inpShapes[i][2], inpShapes[i][3]); + std::swap(inpShapes[i][1], inpShapes[i][2]); + Mat cvInp = tfInp.reshape(1, tfInp.total() / inpShapes[i][1]).t(); + cvInp = cvInp.reshape(1, 4, &inpShapes[i][0]); + + net.setInput(cvInp); + Mat out = net.forward(); + normAssert(tfInp.reshape(1, 3, &outShapes[i][0]), out, "", default_l1, default_lInf); + } +} + INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_layers, dnnBackendsAndTargets()); TEST(Test_TensorFlow, two_inputs) From 92cbec6fb1819561cecbd69f15c36b167deb1c81 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 13 Apr 2019 19:02:03 +0300 Subject: [PATCH 04/16] Fix dnn with IE from GitHub --- modules/dnn/src/op_inf_engine.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index 7e6fcaf1c694..e5c817056b92 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -12,9 +12,6 @@ #ifdef HAVE_INF_ENGINE #include #include -#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5) -#include -#endif #endif // HAVE_INF_ENGINE #include @@ -737,8 +734,7 @@ static bool detectMyriadX_() auto plugin = InferenceEngine::InferencePlugin(enginePtr); try { - auto netExec = plugin.LoadNetwork(cnn, {{InferenceEngine::VPUConfigParams::KEY_VPU_PLATFORM, - InferenceEngine::VPUConfigParams::VPU_2480}}); + auto netExec = plugin.LoadNetwork(cnn, {{"VPU_PLATFORM", "VPU_2480"}}); auto infRequest = netExec.CreateInferRequest(); } catch(...) { return false; From ef16e4203ecb8ca789964163792f46a300933364 Mon Sep 17 00:00:00 2001 From: Manolis Stamatogiannakis Date: Fri, 12 Apr 2019 02:36:59 +0100 Subject: [PATCH 05/16] Fix compile error with external TBB and -DBUILD_SHARED_LIBS=OFF. Adds IMPORTED for the TBB::tbb alias target as otherwise cmake produces the following error: CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_core" which requires target "tbb" that is not in the export set. This problem occurs with the defaults used by homebrew on macOS, which compiles both static and shared versions of TBB and OpenCV. --- cmake/OpenCVDetectTBB.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVDetectTBB.cmake b/cmake/OpenCVDetectTBB.cmake index a9afe7695067..403b446116c6 100644 --- a/cmake/OpenCVDetectTBB.cmake +++ b/cmake/OpenCVDetectTBB.cmake @@ -29,8 +29,10 @@ function(ocv_tbb_cmake_guess _found) message(STATUS "Found TBB (cmake): ${_lib}") get_target_property(_inc TBB::tbb INTERFACE_INCLUDE_DIRECTORIES) ocv_tbb_read_version("${_inc}") - add_library(tbb INTERFACE) - target_link_libraries(tbb INTERFACE TBB::tbb) + add_library(tbb INTERFACE IMPORTED) + set_target_properties(tbb PROPERTIES + INTERFACE_LINK_LIBRARIES TBB::tbb + ) set(${_found} TRUE PARENT_SCOPE) endif() endfunction() From 64fd1c95a579fdb73513291fe5e695ce8a474ddf Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 13 Apr 2019 21:08:06 +0000 Subject: [PATCH 06/16] ts: flush stdout/stderr before test launch --- modules/ts/src/ts.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 41f4207e51f9..810825bca62a 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -755,6 +755,7 @@ static uint64_t memory_usage_base_opencl = 0; void testSetUp() { + fflush(stdout); fflush(stderr); cv::ipp::setIppStatus(0); cv::theRNG().state = cvtest::param_seed; cv::setNumThreads(cvtest::testThreads); From 246733382f8558c7ea2eafda82f8bf28380fd455 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 14 Apr 2019 12:22:57 -0700 Subject: [PATCH 07/16] Fix OpenCVConfig.cmake for Arch Linux. --- cmake/templates/OpenCVConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index fefa359e0a9d..c255fc267728 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -76,7 +76,7 @@ endif() # Extract the directory where *this* file has been installed (determined at cmake run-time) # Get the absolute path with no ../.. relative marks, to eliminate implicit linker warnings -set(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}") +get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH) get_filename_component(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/@OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE@" REALPATH) # Search packages for host system instead of packages for target system. From 78384d89230edad0460e960d624b0ae31abc1388 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 15 Apr 2019 18:59:51 +0000 Subject: [PATCH 08/16] build: avoid highgui dependency --- modules/calib3d/CMakeLists.txt | 6 +++++- modules/calib3d/src/calibinit.cpp | 1 + modules/calib3d/src/circlesgrid.cpp | 2 ++ modules/features2d/CMakeLists.txt | 6 +++++- modules/features2d/src/blobdetector.cpp | 28 +++++++++++-------------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/modules/calib3d/CMakeLists.txt b/modules/calib3d/CMakeLists.txt index b79944da5904..cba3f811b5a6 100644 --- a/modules/calib3d/CMakeLists.txt +++ b/modules/calib3d/CMakeLists.txt @@ -1,2 +1,6 @@ set(the_description "Camera Calibration and 3D Reconstruction") -ocv_define_module(calib3d opencv_imgproc opencv_features2d WRAP java python) +set(debug_modules "") +if(DEBUG_opencv_calib3d) + list(APPEND debug_modules opencv_highgui) +endif() +ocv_define_module(calib3d opencv_imgproc opencv_features2d ${debug_modules} WRAP java python) diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index ade9c71ebb51..863f480b4bc4 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -76,6 +76,7 @@ //#define ENABLE_TRIM_COL_ROW +// Requires CMake flag: DEBUG_opencv_calib3d=ON //#define DEBUG_CHESSBOARD #define DEBUG_CHESSBOARD_TIMEOUT 0 // 0 - wait for 'q' diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index e19a719c8d37..d86d22b2050e 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -43,6 +43,8 @@ #include "precomp.hpp" #include "circlesgrid.hpp" #include + + // Requires CMake flag: DEBUG_opencv_calib3d=ON //#define DEBUG_CIRCLES #ifdef DEBUG_CIRCLES diff --git a/modules/features2d/CMakeLists.txt b/modules/features2d/CMakeLists.txt index f18f69edb397..e92309db0fce 100644 --- a/modules/features2d/CMakeLists.txt +++ b/modules/features2d/CMakeLists.txt @@ -1,2 +1,6 @@ set(the_description "2D Features Framework") -ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python js) +set(debug_modules "") +if(DEBUG_opencv_features2d) + list(APPEND debug_modules opencv_highgui) +endif() +ocv_define_module(features2d opencv_imgproc ${debug_modules} OPTIONAL opencv_flann WRAP java python js) diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index f1e8b637999d..403a8974cc9a 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -44,15 +44,11 @@ #include #include +// Requires CMake flag: DEBUG_opencv_features2d=ON //#define DEBUG_BLOB_DETECTOR #ifdef DEBUG_BLOB_DETECTOR -# include "opencv2/opencv_modules.hpp" -# ifdef HAVE_OPENCV_HIGHGUI -# include "opencv2/highgui.hpp" -# else -# undef DEBUG_BLOB_DETECTOR -# endif +#include "opencv2/highgui.hpp" #endif namespace cv @@ -200,13 +196,13 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag findContours(binaryImage, contours, RETR_LIST, CHAIN_APPROX_NONE); #ifdef DEBUG_BLOB_DETECTOR - // Mat keypointsImage; - // cvtColor( binaryImage, keypointsImage, CV_GRAY2RGB ); - // - // Mat contoursImage; - // cvtColor( binaryImage, contoursImage, CV_GRAY2RGB ); - // drawContours( contoursImage, contours, -1, Scalar(0,255,0) ); - // imshow("contours", contoursImage ); + Mat keypointsImage; + cvtColor(binaryImage, keypointsImage, COLOR_GRAY2RGB); + + Mat contoursImage; + cvtColor(binaryImage, contoursImage, COLOR_GRAY2RGB); + drawContours( contoursImage, contours, -1, Scalar(0,255,0) ); + imshow("contours", contoursImage ); #endif for (size_t contourIdx = 0; contourIdx < contours.size(); contourIdx++) @@ -296,12 +292,12 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag #ifdef DEBUG_BLOB_DETECTOR - // circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 ); + circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 ); #endif } #ifdef DEBUG_BLOB_DETECTOR - // imshow("bk", keypointsImage ); - // waitKey(); + imshow("bk", keypointsImage ); + waitKey(); #endif } From 0d747daf47b256187cb4445d87c40625c0406992 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 15 Apr 2019 21:29:17 +0000 Subject: [PATCH 09/16] cmake: use absolute library paths from 'pkgconfig' - drop legacy check_module() macro - drop 'ALIASOF_' --- CMakeLists.txt | 22 +++---- cmake/OpenCVFindLibsGUI.cmake | 24 +++++--- cmake/OpenCVFindLibsPerf.cmake | 5 +- cmake/OpenCVFindLibsVideo.cmake | 102 ++++++++++++++++--------------- cmake/OpenCVUtils.cmake | 67 +++++++++++++------- modules/highgui/CMakeLists.txt | 4 +- modules/imgcodecs/CMakeLists.txt | 4 +- modules/videoio/CMakeLists.txt | 4 +- 8 files changed, 132 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c639e6067c16..759de6ece64b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1326,15 +1326,15 @@ endif() if(WITH_GTK OR HAVE_GTK) if(HAVE_GTK3) - status(" GTK+:" "YES (ver ${ALIASOF_gtk+-3.0_VERSION})") + status(" GTK+:" "YES (ver ${GTK3_VERSION})") elseif(HAVE_GTK) - status(" GTK+:" "YES (ver ${ALIASOF_gtk+-2.0_VERSION})") + status(" GTK+:" "YES (ver ${GTK2_VERSION})") else() status(" GTK+:" "NO") endif() if(HAVE_GTK) - status( " GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) - status( " GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) + status( " GThread :" HAVE_GTHREAD THEN "YES (ver ${GTHREAD_VERSION})" ELSE NO) + status( " GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${GTKGLEXT_VERSION})" ELSE NO) endif() endif() @@ -1411,9 +1411,9 @@ endif() if(WITH_1394 OR HAVE_DC1394) if (HAVE_DC1394_2) - status(" DC1394:" "YES (ver ${ALIASOF_libdc1394-2_VERSION})") + status(" DC1394:" "YES (ver ${DC1394_2_VERSION})") elseif (HAVE_DC1394) - status(" DC1394:" "YES (ver ${ALIASOF_libdc1394_VERSION})") + status(" DC1394:" "YES (ver ${DC1394_VERSION})") else() status(" DC1394:" "NO") endif() @@ -1435,7 +1435,7 @@ if(WITH_FFMPEG OR HAVE_FFMPEG) endif() if(WITH_GSTREAMER OR HAVE_GSTREAMER) - status(" GStreamer:" HAVE_GSTREAMER THEN "" ELSE NO) + status(" GStreamer:" HAVE_GSTREAMER THEN "YES" ELSE NO) if(HAVE_GSTREAMER) status(" base:" "YES (ver ${GSTREAMER_BASE_VERSION})") status(" video:" "YES (ver ${GSTREAMER_VIDEO_VERSION})") @@ -1477,12 +1477,12 @@ if(APPLE) endif() if(WITH_UNICAP OR HAVE_UNICAP) - status(" UniCap:" HAVE_UNICAP THEN "YES (ver ${ALIASOF_libunicap_VERSION})" ELSE NO) - status(" UniCap ucil:" HAVE_UNICAP_UCIL THEN "YES (ver ${ALIASOF_libucil_VERSION})" ELSE NO) + status(" UniCap:" HAVE_UNICAP THEN "YES (ver ${UNICAP_libunicap_VERSION})" ELSE NO) + status(" UniCap ucil:" HAVE_UNICAP THEN "YES (ver ${UNICAP_libucil_VERSION})" ELSE NO) endif() if(WITH_V4L OR WITH_LIBV4L OR HAVE_LIBV4L OR HAVE_CAMV4L OR HAVE_CAMV4L2 OR HAVE_VIDEOIO) - status(" libv4l/libv4l2:" HAVE_LIBV4L THEN "${ALIASOF_libv4l1_VERSION} / ${ALIASOF_libv4l2_VERSION}" ELSE "NO") + status(" libv4l/libv4l2:" HAVE_LIBV4L THEN "${LIBV4L_libv4l1_VERSION} / ${LIBV4L_libv4l2_VERSION}" ELSE "NO") ocv_build_features_string(v4l_status IF HAVE_CAMV4L THEN "linux/videodev.h" IF HAVE_CAMV4L2 THEN "linux/videodev2.h" @@ -1505,7 +1505,7 @@ if(WITH_XIMEA OR HAVE_XIMEA) endif() if(WITH_XINE OR HAVE_XINE) - status(" Xine:" HAVE_XINE THEN "YES (ver ${ALIASOF_libxine_VERSION})" ELSE NO) + status(" Xine:" HAVE_XINE THEN "YES (ver ${XINE_VERSION})" ELSE NO) endif() if(WITH_INTELPERC OR HAVE_INTELPERC) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index efabb3ce158c..5f861896b528 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -42,24 +42,34 @@ endif() ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) - CHECK_MODULE(gtk+-3.0 HAVE_GTK3 HIGHGUI) + ocv_check_modules(GTK3 gtk+-3.0) if(HAVE_GTK3) + ocv_append_build_options(HIGHGUI GTK3) set(HAVE_GTK TRUE) endif() endif() if(NOT HAVE_GTK) - CHECK_MODULE(gtk+-2.0 HAVE_GTK HIGHGUI) - if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) - message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") - set(HAVE_GTK FALSE) + ocv_check_modules(GTK2 gtk+-2.0) + if(HAVE_GTK2) + if (GTK2_VERSION VERSION_LESS MIN_VER_GTK) + message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)") + else() + ocv_append_build_options(HIGHGUI GTK2) + set(HAVE_GTK TRUE) + endif() endif() endif() - CHECK_MODULE(gthread-2.0 HAVE_GTHREAD HIGHGUI) + ocv_check_modules(GTHREAD gthread-2.0) if(HAVE_GTK AND NOT HAVE_GTHREAD) message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") + else() + ocv_append_build_options(HIGHGUI GTHREAD) endif() if(WITH_OPENGL AND NOT HAVE_GTK3) - CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT HIGHGUI) + ocv_check_modules(GTKGLEXT gtkglext-1.0) + if(HAVE_GTKGLEXT) + ocv_append_build_options(GTKGLEXT GTHREAD) + endif() endif() endif() diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake index 8b91a2d739b1..67978f9210b3 100644 --- a/cmake/OpenCVFindLibsPerf.cmake +++ b/cmake/OpenCVFindLibsPerf.cmake @@ -59,14 +59,13 @@ endif(WITH_EIGEN) ocv_clear_vars(HAVE_CLP) if(WITH_CLP) if(UNIX) - PKG_CHECK_MODULES(CLP clp) + ocv_check_modules(CLP clp) if(CLP_FOUND) set(HAVE_CLP TRUE) if(NOT ${CLP_INCLUDE_DIRS} STREQUAL "") ocv_include_directories(${CLP_INCLUDE_DIRS}) endif() - link_directories(${CLP_LIBRARY_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CLP_LIBRARIES}) + list(APPEND OPENCV_LINKER_LIBS ${CLP_LIBRARIES}) endif() endif() diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index c9f593fbdaa9..b9cc02d05c51 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -27,50 +27,41 @@ if(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10) ENDIF(GSTREAMER_gstbase_LIBRARY AND GSTREAMER_gstvideo_LIBRARY AND GSTREAMER_gstapp_LIBRARY AND GSTREAMER_gstpbutils_LIBRARY AND GSTREAMER_gstriff_LIBRARY) else(WIN32) - CHECK_MODULE(gstreamer-base-1.0 HAVE_GSTREAMER_BASE VIDEOIO) - CHECK_MODULE(gstreamer-video-1.0 HAVE_GSTREAMER_VIDEO VIDEOIO) - CHECK_MODULE(gstreamer-app-1.0 HAVE_GSTREAMER_APP VIDEOIO) - CHECK_MODULE(gstreamer-riff-1.0 HAVE_GSTREAMER_RIFF VIDEOIO) - CHECK_MODULE(gstreamer-pbutils-1.0 HAVE_GSTREAMER_PBUTILS VIDEOIO) - - if(HAVE_GSTREAMER_BASE AND HAVE_GSTREAMER_VIDEO AND HAVE_GSTREAMER_APP AND HAVE_GSTREAMER_RIFF AND HAVE_GSTREAMER_PBUTILS) + ocv_check_modules(GSTREAMER-1.0 gstreamer-base-1.0 gstreamer-video-1.0 gstreamer-app-1.0 gstreamer-riff-1.0 gstreamer-pbutils-1.0) + if(HAVE_GSTREAMER-1.0) set(HAVE_GSTREAMER TRUE) - set(GSTREAMER_BASE_VERSION ${ALIASOF_gstreamer-base-1.0_VERSION}) - set(GSTREAMER_VIDEO_VERSION ${ALIASOF_gstreamer-video-1.0_VERSION}) - set(GSTREAMER_APP_VERSION ${ALIASOF_gstreamer-app-1.0_VERSION}) - set(GSTREAMER_RIFF_VERSION ${ALIASOF_gstreamer-riff-1.0_VERSION}) - set(GSTREAMER_PBUTILS_VERSION ${ALIASOF_gstreamer-pbutils-1.0_VERSION}) + ocv_append_build_options(VIDEOIO GSTREAMER-1.0) + set(GSTREAMER_BASE_VERSION ${GSTREAMER-1.0_gstreamer-base-1.0_VERSION}) + set(GSTREAMER_VIDEO_VERSION ${GSTREAMER-1.0_gstreamer-video-1.0_VERSION}) + set(GSTREAMER_APP_VERSION ${GSTREAMER-1.0_gstreamer-app-1.0_VERSION}) + set(GSTREAMER_RIFF_VERSION ${GSTREAMER-1.0_gstreamer-riff-1.0_VERSION}) + set(GSTREAMER_PBUTILS_VERSION ${GSTREAMER-1.0_gstreamer-pbutils-1.0_VERSION}) endif() endif(WIN32) -endif(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10) +endif() # if gstreamer 1.x was not found, or we specified we wanted 0.10, try to find it if(WITH_GSTREAMER AND NOT HAVE_GSTREAMER OR WITH_GSTREAMER_0_10) - CHECK_MODULE(gstreamer-base-0.10 HAVE_GSTREAMER_BASE VIDEOIO) - CHECK_MODULE(gstreamer-video-0.10 HAVE_GSTREAMER_VIDEO VIDEOIO) - CHECK_MODULE(gstreamer-app-0.10 HAVE_GSTREAMER_APP VIDEOIO) - CHECK_MODULE(gstreamer-riff-0.10 HAVE_GSTREAMER_RIFF VIDEOIO) - CHECK_MODULE(gstreamer-pbutils-0.10 HAVE_GSTREAMER_PBUTILS VIDEOIO) - - if(HAVE_GSTREAMER_BASE AND HAVE_GSTREAMER_VIDEO AND HAVE_GSTREAMER_APP AND HAVE_GSTREAMER_RIFF AND HAVE_GSTREAMER_PBUTILS) - set(HAVE_GSTREAMER TRUE) - set(GSTREAMER_BASE_VERSION ${ALIASOF_gstreamer-base-0.10_VERSION}) - set(GSTREAMER_VIDEO_VERSION ${ALIASOF_gstreamer-video-0.10_VERSION}) - set(GSTREAMER_APP_VERSION ${ALIASOF_gstreamer-app-0.10_VERSION}) - set(GSTREAMER_RIFF_VERSION ${ALIASOF_gstreamer-riff-0.10_VERSION}) - set(GSTREAMER_PBUTILS_VERSION ${ALIASOF_gstreamer-pbutils-0.10_VERSION}) + ocv_check_modules(GSTREAMER-0.10 gstreamer-base-0.10 gstreamer-video-0.10 gstreamer-app-0.10 gstreamer-riff-0.10 gstreamer-pbutils-0.10) + if(HAVE_GSTREAMER-0.10) + set(HAVE_GSTREAMER TRUE) + ocv_append_build_options(VIDEOIO GSTREAMER-0.10) + set(GSTREAMER_BASE_VERSION ${GSTREAMER-0.10_gstreamer-base-0.10_VERSION}) + set(GSTREAMER_VIDEO_VERSION ${GSTREAMER-0.10_gstreamer-video-0.10_VERSION}) + set(GSTREAMER_APP_VERSION ${GSTREAMER-0.10_gstreamer-app-0.10_VERSION}) + set(GSTREAMER_RIFF_VERSION ${GSTREAMER-0.10_gstreamer-riff-0.10_VERSION}) + set(GSTREAMER_PBUTILS_VERSION ${GSTREAMER-0.10_gstreamer-pbutils-0.10_VERSION}) endif() -endif(WITH_GSTREAMER AND NOT HAVE_GSTREAMER OR WITH_GSTREAMER_0_10) +endif() # --- unicap --- ocv_clear_vars(HAVE_UNICAP) if(WITH_UNICAP) - CHECK_MODULE(libunicap HAVE_UNICAP_ VIDEOIO) - CHECK_MODULE(libucil HAVE_UNICAP_UCIL VIDEOIO) - if(HAVE_UNICAP_ AND HAVE_UNICAP_UCIL) - set(HAVE_UNICAP TRUE) + ocv_check_modules(HAVE_UNICAP libunicap libucil) + if(HAVE_UNICAP) + ocv_append_build_options(VIDEOIO UNICAP) endif() -endif(WITH_UNICAP) +endif() # --- PvApi --- ocv_clear_vars(HAVE_PVAPI) @@ -120,7 +111,7 @@ endif(WITH_GIGEAPI) # --- Aravis SDK --- ocv_clear_vars(HAVE_ARAVIS_API) if(WITH_ARAVIS) - check_module(glib-2.0 HAVE_ARAVIS_GLIB VIDEOIO) + ocv_check_modules(ARAVIS_GLIB glib-2.0) if(HAVE_ARAVIS_GLIB) find_path(ARAVIS_INCLUDE_PATH "arv.h" PATHS /usr/local /var /opt /usr ENV ProgramFiles ENV ProgramW6432 @@ -128,6 +119,7 @@ if(WITH_ARAVIS) DOC "The path to Aravis SDK headers") find_library(ARAVIS_LIBRARIES NAMES "aravis-0.6" "aravis-0.4" ) if(ARAVIS_LIBRARIES AND ARAVIS_INCLUDE_PATH) + ocv_append_build_options(VIDEOIO ARAVIS_GLIB) set(HAVE_ARAVIS_API TRUE) endif() else() @@ -139,6 +131,7 @@ endif(WITH_ARAVIS) ocv_clear_vars(HAVE_DC1394 HAVE_DC1394_2) if(WITH_1394) if(WIN32 AND MINGW) + # TODO remove this, use pkgconfig from MinGW instead find_path(CMU1394_INCLUDE_PATH "/1394common.h" PATH_SUFFIXES include DOC "The path to cmu1394 headers") @@ -153,36 +146,42 @@ if(WITH_1394) endif() endif() if(HAVE_DC1394_2) - ocv_parse_pkg("libdc1394-2" "${DC1394_2_LIB_DIR}/pkgconfig" "") + ocv_parse_pkg(DC1394_2_VERSION "libdc1394-2" "${DC1394_2_LIB_DIR}/pkgconfig") ocv_include_directories(${DC1394_2_INCLUDE_PATH}) set(VIDEOIO_LIBRARIES ${VIDEOIO_LIBRARIES} "${DC1394_2_LIB_DIR}/libdc1394.a" "${CMU1394_LIB_DIR}/lib1394camera.a") - endif(HAVE_DC1394_2) - else(WIN32 AND MINGW) - CHECK_MODULE(libdc1394-2 HAVE_DC1394_2 VIDEOIO) - if(NOT HAVE_DC1394_2) - CHECK_MODULE(libdc1394 HAVE_DC1394 VIDEOIO) + endif() + endif() + if(NOT HAVE_DC1394_2) + ocv_check_modules(DC1394_2 libdc1394-2) + if(HAVE_DC1394_2) + ocv_append_build_options(VIDEOIO DC1394_2) + else() + ocv_check_modules(DC1394 libdc1394) + if(HAVE_DC1394) + ocv_append_build_options(VIDEOIO DC1394) + endif() endif() - endif(WIN32 AND MINGW) -endif(WITH_1394) + endif() +endif() # --- xine --- ocv_clear_vars(HAVE_XINE) if(WITH_XINE) - CHECK_MODULE(libxine HAVE_XINE VIDEOIO) + ocv_check_modules(XINE libxine) + if(HAVE_XINE) + ocv_append_build_options(VIDEOIO XINE) + endif() endif(WITH_XINE) # --- V4L --- ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_VIDEOIO) if(WITH_V4L) if(WITH_LIBV4L) - CHECK_MODULE(libv4l1 HAVE_LIBV4L1 VIDEOIO) - CHECK_MODULE(libv4l2 HAVE_LIBV4L2 VIDEOIO) - if(HAVE_LIBV4L1 AND HAVE_LIBV4L2) - set(HAVE_LIBV4L YES) - else() - set(HAVE_LIBV4L NO) + ocv_check_modules(LIBV4L libv4l1 libv4l2) + if(HAVE_LIBV4L) + ocv_append_build_options(VIDEOIO LIBV4L) endif() endif() CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L) @@ -323,8 +322,11 @@ endif() # --- gPhoto2 --- ocv_clear_vars(HAVE_GPHOTO2) if(WITH_GPHOTO2) - CHECK_MODULE(libgphoto2 HAVE_GPHOTO2 VIDEOIO) -endif(WITH_GPHOTO2) + ocv_check_modules(GPHOTO2 libgphoto2) + if(HAVE_GPHOTO2) + ocv_append_build_options(VIDEOIO GPHOTO2) + endif() +endif() # --- VA & VA_INTEL --- if(WITH_VA_INTEL) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 5772ca8d76c7..6c5b44b009ec 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -701,7 +701,7 @@ endfunction() # Usage: ocv_append_build_options(HIGHGUI FFMPEG) macro(ocv_append_build_options var_prefix pkg_prefix) - foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS) + foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS LINK_LIBRARIES) if(${pkg_prefix}_${suffix}) list(APPEND ${var_prefix}_${suffix} ${${pkg_prefix}_${suffix}}) list(REMOVE_DUPLICATES ${var_prefix}_${suffix}) @@ -739,7 +739,9 @@ macro(ocv_check_modules define) endif() unset(${define}_${__modname}_FOUND) endforeach() - pkg_check_modules(${define} ${ARGN}) + if(COMMAND pkg_check_modules) + pkg_check_modules(${define} ${ARGN}) + endif() if(${define}_FOUND) set(HAVE_${define} 1) endif() @@ -753,29 +755,47 @@ macro(ocv_check_modules define) set(${define}_${__modname}_FOUND 1) endif() endforeach() -endmacro() - - -# Macro that checks if module has been installed. -# After it adds module to build and define -# constants passed as second arg -macro(CHECK_MODULE module_name define cv_module) - set(${define} 0) - if(PKG_CONFIG_FOUND) - set(ALIAS ALIASOF_${module_name}) - set(ALIAS_FOUND ${ALIAS}_FOUND) - set(ALIAS_INCLUDE_DIRS ${ALIAS}_INCLUDE_DIRS) - set(ALIAS_LIBRARY_DIRS ${ALIAS}_LIBRARY_DIRS) - set(ALIAS_LIBRARIES ${ALIAS}_LIBRARIES) - - PKG_CHECK_MODULES(${ALIAS} ${module_name}) - if(${ALIAS_FOUND}) - set(${define} 1) - ocv_append_build_options(${cv_module} ${ALIAS}) + if(${define}_FOUND AND ${define}_LIBRARIES) + if(${define}_LINK_LIBRARIES_XXXXX) # CMake 3.12+: https://gitlab.kitware.com/cmake/cmake/merge_requests/2068 + set(${define}_LIBRARIES "${${define}_LINK_LIBRARIES}" CACHE INTERNAL "") + else() + unset(_libs) # absolute paths + unset(_libs_paths) # -L args + foreach(flag ${${define}_LDFLAGS}) + if(flag MATCHES "^-L(.*)") + list(APPEND _libs_paths ${CMAKE_MATCH_1}) + elseif(IS_ABSOLUTE "${flag}") + list(APPEND _libs "${flag}") + elseif(flag MATCHES "^-l(.*)") + set(_lib "${CMAKE_MATCH_1}") + if(_libs_paths) + find_library(pkgcfg_lib_${define}_${_lib} NAMES ${_lib} + HINTS ${_libs_paths} NO_DEFAULT_PATH) + endif() + find_library(pkgcfg_lib_${define}_${_lib} NAMES ${_lib}) + mark_as_advanced(pkgcfg_lib_${define}_${_lib}) + if(pkgcfg_lib_${define}_${_lib}) + list(APPEND _libs "${pkgcfg_lib_${define}_${_lib}}") + else() + message(WARNING "ocv_check_modules(${define}): can't find library '${_lib}'. Specify 'pkgcfg_lib_${define}_${_lib}' manualy") + list(APPEND _libs "${_lib}") + endif() + else() + # -pthread + #message(WARNING "ocv_check_modules(${define}): unknown LDFLAG '${flag}'") + endif() + endforeach() + set(${define}_LINK_LIBRARIES "${_libs}") + set(${define}_LIBRARIES "${_libs}" CACHE INTERNAL "") + unset(_lib) + unset(_libs) + unset(_libs_paths) endif() endif() endmacro() + + if(NOT DEFINED CMAKE_ARGC) # Guard CMake standalone invocations # Use this option carefully, CMake's install() will install symlinks instead of real files @@ -1290,11 +1310,12 @@ macro(ocv_parse_header2 LIBNAME HDR_PATH VARNAME) endif() endmacro() +# TODO remove this # read single version info from the pkg file -macro(ocv_parse_pkg LIBNAME PKG_PATH SCOPE) +macro(ocv_parse_pkg ver_varname LIBNAME PKG_PATH) if(EXISTS "${PKG_PATH}/${LIBNAME}.pc") file(STRINGS "${PKG_PATH}/${LIBNAME}.pc" line_to_parse REGEX "^Version:[ \t]+[0-9.]*.*$" LIMIT_COUNT 1) - STRING(REGEX REPLACE ".*Version: ([^ ]+).*" "\\1" ALIASOF_${LIBNAME}_VERSION "${line_to_parse}" ) + STRING(REGEX REPLACE ".*Version: ([^ ]+).*" "\\1" ${ver_varname} "${line_to_parse}" ) endif() endmacro() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index af54d9c3a085..e02c55deb8cf 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -128,8 +128,8 @@ elseif(HAVE_COCOA) list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa") endif() -if(UNIX) - #these variables are set by CHECK_MODULE macro +if(TRUE) + # these variables are set by 'ocv_append_build_options(HIGHGUI ...)' foreach(P ${HIGHGUI_INCLUDE_DIRS}) ocv_include_directories(${P}) endforeach() diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index f83a12da736a..50354769e634 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -111,8 +111,8 @@ if(APPLE_FRAMEWORK) list(APPEND IMGCODECS_LIBRARIES "-framework UIKit") endif() -if(UNIX) - #these variables are set by CHECK_MODULE macro +if(TRUE) + # these variables are set by 'ocv_append_build_options(IMGCODECS ...)' foreach(P ${IMGCODECS_INCLUDE_DIRS}) ocv_include_directories(${P}) endforeach() diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 08c39677064f..d3f24b65ccda 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -233,8 +233,8 @@ if(IOS) list(APPEND VIDEOIO_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework UIKit") endif() -if(UNIX) - #these variables are set by CHECK_MODULE macro +if(TRUE) + # these variables are set by 'ocv_append_build_options(VIDEOIO ...)' foreach(P ${VIDEOIO_INCLUDE_DIRS}) ocv_include_directories(${P}) endforeach() From 3902694075a71287c8ef8e8444890e8e2b91a8ae Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 16 Apr 2019 06:49:47 +0000 Subject: [PATCH 10/16] static scans: preserve namespace name --- modules/dnn/include/opencv2/dnn/dnn.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp index 700bd5f32497..6f80597c70ef 100644 --- a/modules/dnn/include/opencv2/dnn/dnn.hpp +++ b/modules/dnn/include/opencv2/dnn/dnn.hpp @@ -45,7 +45,7 @@ #include #include -#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS +#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS #define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v11 { #define CV__DNN_EXPERIMENTAL_NS_END } namespace cv { namespace dnn { namespace experimental_dnn_34_v11 { } using namespace experimental_dnn_34_v11; }} From 62d079fa699aed6a1e2fe6e9ad3b4de368a95146 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Tue, 16 Apr 2019 11:41:50 +0300 Subject: [PATCH 11/16] Fix Normalize layer for Mac --- .../dnn/src/layers/normalize_bbox_layer.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/dnn/src/layers/normalize_bbox_layer.cpp b/modules/dnn/src/layers/normalize_bbox_layer.cpp index 8760cad33bbe..65640b69053d 100644 --- a/modules/dnn/src/layers/normalize_bbox_layer.cpp +++ b/modules/dnn/src/layers/normalize_bbox_layer.cpp @@ -275,13 +275,13 @@ class NormalizeBBoxLayerImpl CV_FINAL : public NormalizeBBoxLayer InferenceEngine::Blob::Ptr weights; if (blobs.empty()) { - auto onesBlob = InferenceEngine::make_shared_blob(InferenceEngine::Precision::FP32, - InferenceEngine::Layout::C, - {(size_t)numChannels}); - onesBlob->allocate(); - std::vector ones(numChannels, 1); - onesBlob->set(ones); - weights = onesBlob; + weights = InferenceEngine::make_shared_blob(InferenceEngine::Precision::FP32, + InferenceEngine::Layout::C, + {(size_t)numChannels}); + weights->allocate(); + + Mat weightsMat = infEngineBlobToMat(weights).reshape(1, numChannels); + Mat(numChannels, 1, CV_32F, Scalar(1)).copyTo(weightsMat); l.getParameters()["channel_shared"] = false; } else @@ -290,11 +290,7 @@ class NormalizeBBoxLayerImpl CV_FINAL : public NormalizeBBoxLayer weights = wrapToInfEngineBlob(blobs[0], {(size_t)numChannels}, InferenceEngine::Layout::C); l.getParameters()["channel_shared"] = blobs[0].total() == 1; } -#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2019R1) - l.getParameters()["weights"] = weights; -#else - l.addConstantData("weights", weights); -#endif + addConstantData("weights", weights, l); l.getParameters()["across_spatial"] = acrossSpatial; return Ptr(new InfEngineBackendNode(l)); } From a30406968717eba068b2955eacf9763674001480 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Tue, 16 Apr 2019 13:10:31 +0300 Subject: [PATCH 12/16] Remove preprocessing parameters from README --- samples/dnn/README.md | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/samples/dnn/README.md b/samples/dnn/README.md index 94460b3c0c81..60fa09338105 100644 --- a/samples/dnn/README.md +++ b/samples/dnn/README.md @@ -2,19 +2,22 @@ ## Model Zoo -### Object detection - -| Model | Scale | Size WxH| Mean subtraction | Channels order | -|---------------|-------|-----------|--------------------|-------| -| [MobileNet-SSD, Caffe](https://github.com/chuanqi305/MobileNet-SSD/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | BGR | -| [OpenCV face detector](https://github.com/opencv/opencv/tree/3.4/samples/dnn/face_detector) | `1.0` | `300x300` | `104 177 123` | BGR | -| [SSDs from TensorFlow](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | RGB | -| [YOLO](https://pjreddie.com/darknet/yolo/) | `0.00392 (1/255)` | `416x416` | `0 0 0` | RGB | -| [VGG16-SSD](https://github.com/weiliu89/caffe/tree/ssd) | `1.0` | `300x300` | `104 117 123` | BGR | -| [Faster-RCNN](https://github.com/rbgirshick/py-faster-rcnn) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR | -| [R-FCN](https://github.com/YuwenXiong/py-R-FCN) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR | -| [Faster-RCNN, ResNet backbone](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `1.0` | `300x300` | `103.939 116.779 123.68` | RGB | -| [Faster-RCNN, InceptionV2 backbone](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | RGB | +Check [a wiki](https://github.com/opencv/opencv/wiki/Deep-Learning-in-OpenCV) for a list of tested models. + +If OpenCV is built with [Intel's Inference Engine support](https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend) you can use [Intel's pre-trained](https://github.com/opencv/open_model_zoo) models. + +There are different preprocessing parameters such mean subtraction or scale factors for different models. +You may check the most popular models and their parameters at [models.yml](https://github.com/opencv/opencv/blob/master/samples/dnn/models.yml) configuration file. It might be also used for aliasing samples parameters. In example, + +```bash +python object_detection.py opencv_fd --model /path/to/caffemodel --config /path/to/prototxt +``` + +Check `-h` option to know which values are used by default: + +```bash +python object_detection.py opencv_fd -h +``` #### Face detection [An origin model](https://github.com/opencv/opencv/tree/3.4/samples/dnn/face_detector) @@ -44,18 +47,6 @@ AR @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] | 0.481 | 0.480 (-0.001) | AR @[ IoU=0.50:0.95 | area= large | maxDets=100 ] | 0.528 | 0.528 | 0.520 | 0.462 (-0.058) | ``` -### Classification -| Model | Scale | Size WxH| Mean subtraction | Channels order | -|---------------|-------|-----------|--------------------|-------| -| GoogLeNet | `1.0` | `224x224` | `104 117 123` | BGR | -| [SqueezeNet](https://github.com/DeepScale/SqueezeNet) | `1.0` | `227x227` | `0 0 0` | BGR | - -### Semantic segmentation -| Model | Scale | Size WxH| Mean subtraction | Channels order | -|---------------|-------|-----------|--------------------|-------| -| [ENet](https://github.com/e-lab/ENet-training) | `0.00392 (1/255)` | `1024x512` | `0 0 0` | RGB | -| FCN8s | `1.0` | `500x500` | `0 0 0` | BGR | - ## References * [Models downloading script](https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/download_models.py) * [Configuration files adopted for OpenCV](https://github.com/opencv/opencv_extra/tree/master/testdata/dnn) From 621e3eaed87e800a064d9e37276e82a0a98791f4 Mon Sep 17 00:00:00 2001 From: LaurentBerger Date: Mon, 15 Apr 2019 15:51:30 +0200 Subject: [PATCH 13/16] Add Ptr KNearest::load and python binding --- modules/ml/include/opencv2/ml.hpp | 8 ++++++++ modules/ml/misc/python/test/test_knearest.py | 13 +++++++++++++ modules/ml/src/knearest.cpp | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 modules/ml/misc/python/test/test_knearest.py diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 534820645bd5..eab88e0d6409 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -505,6 +505,14 @@ class CV_EXPORTS_W KNearest : public StatModel The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method. */ CV_WRAP static Ptr create(); + /** @brief Loads and creates a serialized knearest from a file + * + * Use KNearest::save to serialize and store an KNearest to disk. + * Load the KNearest from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized KNearest + */ + CV_WRAP static Ptr load(const String& filepath); }; /****************************************************************************************\ diff --git a/modules/ml/misc/python/test/test_knearest.py b/modules/ml/misc/python/test/test_knearest.py new file mode 100644 index 000000000000..8ae0be5f73e8 --- /dev/null +++ b/modules/ml/misc/python/test/test_knearest.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +import cv2 as cv + +from tests_common import NewOpenCVTests + +class knearest_test(NewOpenCVTests): + def test_load(self): + k_nearest = cv.ml.KNearest_load(self.find_file("ml/opencv_ml_knn.xml")) + self.assertFalse(k_nearest.empty()) + self.assertTrue(k_nearest.isTrained()) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/ml/src/knearest.cpp b/modules/ml/src/knearest.cpp index cee7bdfdb005..dcc201158da2 100644 --- a/modules/ml/src/knearest.cpp +++ b/modules/ml/src/knearest.cpp @@ -515,6 +515,17 @@ Ptr KNearest::create() return makePtr(); } +Ptr KNearest::load(const String& filepath) +{ + FileStorage fs; + fs.open(filepath, FileStorage::READ); + + Ptr knearest = makePtr(); + + ((KNearestImpl*)knearest.get())->read(fs.getFirstTopLevelNode()); + return knearest; +} + } } From c667de9b68e10c5bddc64af0355f11932889f61a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 16 Apr 2019 18:13:14 +0300 Subject: [PATCH 14/16] dnn: force visibility(default) for IE headers --- modules/dnn/src/op_inf_engine.hpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/dnn/src/op_inf_engine.hpp b/modules/dnn/src/op_inf_engine.hpp index 48ee07e745c9..2219f926a764 100644 --- a/modules/dnn/src/op_inf_engine.hpp +++ b/modules/dnn/src/op_inf_engine.hpp @@ -15,14 +15,6 @@ #include "opencv2/dnn/utils/inference_engine.hpp" #ifdef HAVE_INF_ENGINE -#if defined(__GNUC__) && __GNUC__ >= 5 -//#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsuggest-override" -#endif -#include -#if defined(__GNUC__) && __GNUC__ >= 5 -//#pragma GCC diagnostic pop -#endif #define INF_ENGINE_RELEASE_2018R3 2018030000 #define INF_ENGINE_RELEASE_2018R4 2018040000 @@ -37,12 +29,32 @@ #define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000)) #define INF_ENGINE_VER_MAJOR_GE(ver) (((INF_ENGINE_RELEASE) / 10000) >= ((ver) / 10000)) #define INF_ENGINE_VER_MAJOR_LT(ver) (((INF_ENGINE_RELEASE) / 10000) < ((ver) / 10000)) +#define INF_ENGINE_VER_MAJOR_LE(ver) (((INF_ENGINE_RELEASE) / 10000) <= ((ver) / 10000)) #define INF_ENGINE_VER_MAJOR_EQ(ver) (((INF_ENGINE_RELEASE) / 10000) == ((ver) / 10000)) +#if defined(__GNUC__) && __GNUC__ >= 5 +//#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsuggest-override" +#endif + +#if defined(__GNUC__) && INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1) +#pragma GCC visibility push(default) +#endif + +#include + #if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5) #include #endif +#if defined(__GNUC__) && INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1) +#pragma GCC visibility pop +#endif + +#if defined(__GNUC__) && __GNUC__ >= 5 +//#pragma GCC diagnostic pop +#endif + #endif // HAVE_INF_ENGINE namespace cv { namespace dnn { From 52f16e0f553c4a9286c814cfa2cc7d6ccbc3c38a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 17 Apr 2019 15:19:33 +0300 Subject: [PATCH 15/16] tests: workaround for DYLD_LIBRARY_PATH on Apple MacOSX --- modules/java/test/pure_test/build.xml | 1 + modules/ts/misc/run_utils.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/modules/java/test/pure_test/build.xml b/modules/java/test/pure_test/build.xml index 7729b41b2b9f..870dd44d74a1 100644 --- a/modules/java/test/pure_test/build.xml +++ b/modules/java/test/pure_test/build.xml @@ -41,6 +41,7 @@ + diff --git a/modules/ts/misc/run_utils.py b/modules/ts/misc/run_utils.py index 4fc84cc8efeb..8c942ba9d18a 100644 --- a/modules/ts/misc/run_utils.py +++ b/modules/ts/misc/run_utils.py @@ -37,6 +37,13 @@ def execute(cmd, silent=False, cwd=".", env=None): new_env = os.environ.copy() new_env.update(env) env = new_env + + if sys.platform == 'darwin': # https://github.com/opencv/opencv/issues/14351 + if env is None: + env = os.environ.copy() + if 'DYLD_LIBRARY_PATH' in env: + env['OPENCV_SAVED_DYLD_LIBRARY_PATH'] = env['DYLD_LIBRARY_PATH'] + if silent: return check_output(cmd, stderr=STDOUT, cwd=cwd, env=env).decode("latin-1") else: From 2e4d771005090952825fbf079dc8057b4e5077f4 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 19 Apr 2019 13:54:51 +0300 Subject: [PATCH 16/16] cmake: fix PDB handling --- cmake/OpenCVUtils.cmake | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 6c5b44b009ec..c530a4c983aa 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1,3 +1,7 @@ +if(COMMAND ocv_cmake_dump_vars) # include guard + return() +endif() + include(CMakeParseArguments) # Debugging function @@ -1111,15 +1115,6 @@ function(ocv_convert_to_lib_name var) set(${var} ${tmp} PARENT_SCOPE) endfunction() -if(MSVC AND BUILD_SHARED_LIBS) # no defaults for static libs (modern CMake is required) - if(NOT CMAKE_VERSION VERSION_LESS 3.6.0) - option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON) - option(INSTALL_PDB "Add install PDB rules" ON) - elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0) - option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF) - option(INSTALL_PDB "Add install PDB rules" OFF) - endif() -endif() # add install command function(ocv_install_target) @@ -1152,6 +1147,18 @@ function(ocv_install_target) if(MSVC) set(__target "${ARGV0}") + + # don't move this into global scope of this file: compiler settings (like MSVC variable) are not available during processing + if(BUILD_SHARED_LIBS) # no defaults for static libs (modern CMake is required) + if(NOT CMAKE_VERSION VERSION_LESS 3.6.0) + option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON) + option(INSTALL_PDB "Add install PDB rules" ON) + elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0) + option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF) + option(INSTALL_PDB "Add install PDB rules" OFF) + endif() + endif() + if(INSTALL_PDB AND NOT INSTALL_IGNORE_PDB AND NOT OPENCV_${__target}_PDB_SKIP ) @@ -1196,7 +1203,7 @@ function(ocv_install_target) endif() # message(STATUS "Adding PDB file installation rule: target=${__target} dst=${__dst} component=${__pdb_install_component}") - if("${__target_type}" STREQUAL "SHARED_LIBRARY") + if("${__target_type}" STREQUAL "SHARED_LIBRARY" OR "${__target_type}" STREQUAL "MODULE_LIBRARY") install(FILES "$" DESTINATION "${__dst}" COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all}) else()