From 7a916886d48988521b4b141ea8ddf0d490d23cce Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Tue, 12 Oct 2021 05:16:42 +0900 Subject: [PATCH 1/3] tolerate the rounding error * edge drawing is NOT bit-exact --- modules/ximgproc/test/test_fld.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ximgproc/test/test_fld.cpp b/modules/ximgproc/test/test_fld.cpp index c308a706d..f19f336a4 100644 --- a/modules/ximgproc/test/test_fld.cpp +++ b/modules/ximgproc/test/test_fld.cpp @@ -292,7 +292,8 @@ TEST_F(ximgproc_ED, ManySmallCircles) size_t lines_size = 6264; size_t ellipses_size = 2449; EXPECT_EQ(detector->getSegments().size(), segments_size); - EXPECT_EQ(lines.size(), lines_size); + EXPECT_GE(lines.size(), lines_size); + EXPECT_LE(lines.size(), lines_size + 2); EXPECT_EQ(ellipses.size(), ellipses_size); } }} // namespace From 496ea61c8d607c657a8bcc471f9e3f5e68aea26d Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Tue, 12 Oct 2021 16:26:26 +0200 Subject: [PATCH 2/3] Do not use = 0 for a cv::Mat. There are several operator= overloads and some compilers can be confused. This is a leftover from https://github.com/opencv/opencv_contrib/pull/2987 --- modules/img_hash/src/radial_variance_hash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/img_hash/src/radial_variance_hash.cpp b/modules/img_hash/src/radial_variance_hash.cpp index 375cb57a1..794d252ce 100644 --- a/modules/img_hash/src/radial_variance_hash.cpp +++ b/modules/img_hash/src/radial_variance_hash.cpp @@ -266,7 +266,7 @@ public: } else { - hash = 0; + hash.setTo(cv::Scalar::all(0)); } } From 31f98132b3e8f61e707ad9536d7f502ef6ab5aa2 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Mon, 11 Oct 2021 00:20:32 +0300 Subject: [PATCH 3/3] update structured forests tutorial --- .../ximgproc/structured_edge_detection.hpp | 16 ++--- .../samples/structured_edge_detection.cpp | 60 ++++++++++++------- .../ximgproc/tutorials/prediction.markdown | 37 +++--------- 3 files changed, 54 insertions(+), 59 deletions(-) diff --git a/modules/ximgproc/include/opencv2/ximgproc/structured_edge_detection.hpp b/modules/ximgproc/include/opencv2/ximgproc/structured_edge_detection.hpp index b0eb777a4..1d375d3a2 100644 --- a/modules/ximgproc/include/opencv2/ximgproc/structured_edge_detection.hpp +++ b/modules/ximgproc/include/opencv2/ximgproc/structured_edge_detection.hpp @@ -102,31 +102,31 @@ public: The algorithm underlies this function is much more robust to texture presence, than common approaches, e.g. Sobel - @param _src source image (RGB, float, in [0;1]) to detect edges - @param _dst destination image (grayscale, float, in [0;1]) where edges are drawn + @param src source image (RGB, float, in [0;1]) to detect edges + @param dst destination image (grayscale, float, in [0;1]) where edges are drawn @sa Sobel, Canny */ - CV_WRAP virtual void detectEdges(cv::InputArray _src, cv::OutputArray _dst) const = 0; + CV_WRAP virtual void detectEdges(cv::InputArray src, cv::OutputArray dst) const = 0; /** @brief The function computes orientation from edge image. - @param _src edge image. - @param _dst orientation image. + @param src edge image. + @param dst orientation image. */ - CV_WRAP virtual void computeOrientation(cv::InputArray _src, cv::OutputArray _dst) const = 0; + CV_WRAP virtual void computeOrientation(cv::InputArray src, cv::OutputArray dst) const = 0; /** @brief The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction. @param edge_image edge image from detectEdges function. @param orientation_image orientation image from computeOrientation function. - @param _dst suppressed image (grayscale, float, in [0;1]) + @param dst suppressed image (grayscale, float, in [0;1]) @param r radius for NMS suppression. @param s radius for boundary suppression. @param m multiplier for conservative suppression. @param isParallel enables/disables parallel computing. */ - CV_WRAP virtual void edgesNms(cv::InputArray edge_image, cv::InputArray orientation_image, cv::OutputArray _dst, int r = 2, int s = 0, float m = 1, bool isParallel = true) const = 0; + CV_WRAP virtual void edgesNms(cv::InputArray edge_image, cv::InputArray orientation_image, cv::OutputArray dst, int r = 2, int s = 0, float m = 1, bool isParallel = true) const = 0; }; /*! diff --git a/modules/ximgproc/samples/structured_edge_detection.cpp b/modules/ximgproc/samples/structured_edge_detection.cpp index 631a3ce47..c9190c2a3 100644 --- a/modules/ximgproc/samples/structured_edge_detection.cpp +++ b/modules/ximgproc/samples/structured_edge_detection.cpp @@ -1,12 +1,11 @@ /************************************************************************************** -The structered edge demo requires you to provide a model. +The structured forests for fast edge detection demo requires you to provide a model. This model can be found at the opencv_extra repository on Github on the following link: https://github.com/opencv/opencv_extra/blob/master/testdata/cv/ximgproc/model.yml.gz ***************************************************************************************/ #include #include "opencv2/highgui.hpp" -#include "opencv2/core/utility.hpp" #include using namespace cv; @@ -14,26 +13,17 @@ using namespace cv::ximgproc; const char* keys = { - "{i || input image name}" - "{m || model name}" - "{o || output image name}" + "{i || input image file name}" + "{m || model file name}" + "{o || output image file name}" }; int main( int argc, const char** argv ) { - bool printHelp = ( argc == 1 ); - printHelp = printHelp || ( argc == 2 && String(argv[1]) == "--help" ); - printHelp = printHelp || ( argc == 2 && String(argv[1]) == "-h" ); - - if ( printHelp ) - { - std::cout << "\nThis sample demonstrates structured forests for fast edge detection\n" - "Call:\n" - " structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n"; - return 0; - } - CommandLineParser parser(argc, argv, keys); + parser.about("This sample demonstrates usage of structured forests for fast edge detection"); + parser.printMessage(); + if ( !parser.check() ) { parser.printErrors(); @@ -44,21 +34,41 @@ int main( int argc, const char** argv ) String inFilename = parser.get("i"); String outFilename = parser.get("o"); - Mat image = imread(inFilename, 1); + //! [imread] + Mat image = imread(inFilename, IMREAD_COLOR); if ( image.empty() ) CV_Error(Error::StsError, String("Cannot read image file: ") + inFilename); + //! [imread] if ( modelFilename.size() == 0) CV_Error(Error::StsError, String("Empty model name")); + //! [convert] image.convertTo(image, DataType::type, 1/255.0); + //! [convert] - Mat edges(image.size(), image.type()); - + TickMeter tm; + tm.start(); + //! [create] Ptr pDollar = createStructuredEdgeDetection(modelFilename); - pDollar->detectEdges(image, edges); + //! [create] + tm.stop(); + std::cout << "createStructuredEdgeDetection() time : " << tm << std::endl; + + tm.reset(); + tm.start(); + //! [detect] + Mat edges; + pDollar->detectEdges(image, edges); + //! [detect] + tm.stop(); + std::cout << "detectEdges() time : " << tm << std::endl; + + tm.reset(); + tm.start(); + //! [nms] // computes orientation from edge map Mat orientation_map; pDollar->computeOrientation(edges, orientation_map); @@ -66,17 +76,21 @@ int main( int argc, const char** argv ) // suppress edges Mat edge_nms; pDollar->edgesNms(edges, orientation_map, edge_nms, 2, 0, 1, true); + //! [nms] + tm.stop(); + std::cout << "nms time : " << tm << std::endl; + + //! [imshow] if ( outFilename.size() == 0 ) { - namedWindow("edges", 1); imshow("edges", edges); - namedWindow("edges nms", 1); imshow("edges nms", edge_nms); waitKey(0); } else imwrite(outFilename, 255*edges); + //! [imshow] return 0; } diff --git a/modules/ximgproc/tutorials/prediction.markdown b/modules/ximgproc/tutorials/prediction.markdown index 9d05c3211..7f1fd8545 100644 --- a/modules/ximgproc/tutorials/prediction.markdown +++ b/modules/ximgproc/tutorials/prediction.markdown @@ -46,41 +46,22 @@ Explanation ----------- -# **Load source color image** - @code{.cpp} - cv::Mat image = cv::imread(inFilename, 1); - if ( image.empty() ) - { - printf("Cannot read image file: %s\n", inFilename.c_str()); - return -1; - } - @endcode --# **Convert source image to [0;1] range** - @code{.cpp} - image.convertTo(image, cv::DataType::type, 1/255.0); - @endcode + @snippet ximgproc/samples/structured_edge_detection.cpp imread + +-# **Convert source image to float [0;1] range** + + @snippet ximgproc/samples/structured_edge_detection.cpp convert -# **Run main algorithm** - @code{.cpp} - cv::Mat edges(image.size(), image.type()); - cv::Ptr pDollar = - cv::createStructuredEdgeDetection(modelFilename); - pDollar->detectEdges(image, edges); - @endcode + @snippet ximgproc/samples/structured_edge_detection.cpp create + @snippet ximgproc/samples/structured_edge_detection.cpp detect + @snippet ximgproc/samples/structured_edge_detection.cpp nms -# **Show results** - @code{.cpp} - if ( outFilename == "" ) - { - cv::namedWindow("edges", 1); - cv::imshow("edges", edges); - cv::waitKey(0); - } - else - cv::imwrite(outFilename, 255*edges); - @endcode + @snippet ximgproc/samples/structured_edge_detection.cpp imshow Literature ----------