From 8bc22eba5946100e9b2470c60939c3f2588c28d7 Mon Sep 17 00:00:00 2001 From: s-trinh Date: Fri, 29 May 2026 08:53:01 +0200 Subject: [PATCH] Merge pull request #29173 from s-trinh:add_parallel_for_tuto_link Add parallel_for_ tutorial (Mandelbrot set) link in the main page #29173 Add the `parallel_for_` tutorial with Mandelbrot set use case in the main page: - the tutorial exists: https://docs.opencv.org/4.13.0/d7/dff/tutorial_how_to_use_OpenCV_parallel_for_.html - but is not listed in the main page: https://docs.opencv.org/4.13.0/de/d7a/tutorial_table_of_content_core.html Some minor cleaning: - removed [C=](https://www.hoopoesnest.com/cstripes/cstripes-sketch.htm) mention - use Web Archive link - prefer https link On my computer (Firefox), the images ([here](https://docs.opencv.org/4.13.0/d3/dc1/tutorial_basic_linear_transform.html)) are shown like this: image When adding a scale parameter, the images are correctly shown: image This is odd. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- .../core/adding_images/adding_images.markdown | 2 +- .../basic_linear_transform.markdown | 6 ++-- .../file_input_output_with_xml_yml.markdown | 1 + .../how_to_use_OpenCV_parallel_for_.markdown | 28 ++++++++++--------- ...ow_to_use_OpenCV_parallel_for_new.markdown | 5 ++-- .../core/table_of_content_core.markdown | 1 + ...sian_median_blur_bilateral_filter.markdown | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/tutorials/core/adding_images/adding_images.markdown b/doc/tutorials/core/adding_images/adding_images.markdown index 90679a1b39..8e91688c99 100644 --- a/doc/tutorials/core/adding_images/adding_images.markdown +++ b/doc/tutorials/core/adding_images/adding_images.markdown @@ -25,7 +25,7 @@ Theory @note The explanation below belongs to the book [Computer Vision: Algorithms and - Applications](http://szeliski.org/Book/) by Richard Szeliski + Applications](https://szeliski.org/Book/) by Richard Szeliski From our previous tutorial, we already know a bit of *Pixel operators*. An interesting dyadic (two-input) operator is the *linear blend operator*: diff --git a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown index 0f569a41b2..10381f6180 100644 --- a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown +++ b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.markdown @@ -27,7 +27,7 @@ Theory @note The explanation below belongs to the book [Computer Vision: Algorithms and - Applications](http://szeliski.org/Book/) by Richard Szeliski + Applications](https://szeliski.org/Book/) by Richard Szeliski ### Image Processing @@ -266,14 +266,14 @@ be the opposite with \f$ \gamma > 1 \f$. The following image has been corrected with: \f$ \alpha = 1.3 \f$ and \f$ \beta = 40 \f$. -![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_linear_transform_correction.jpg) +![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_linear_transform_correction.jpg) { width=90% } The overall brightness has been improved but you can notice that the clouds are now greatly saturated due to the numerical saturation of the implementation used ([highlight clipping](https://en.wikipedia.org/wiki/Clipping_(photography)) in photography). The following image has been corrected with: \f$ \gamma = 0.4 \f$. -![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_gamma_correction.jpg) +![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_gamma_correction.jpg) { width=90% } The gamma correction should tend to add less saturation effect as the mapping is non linear and there is no numerical saturation possible as in the previous method. diff --git a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown index cb6e33e981..2dde00a38d 100644 --- a/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown +++ b/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.markdown @@ -4,6 +4,7 @@ File Input and Output using XML / YAML / JSON files {#tutorial_file_input_output @tableofcontents @prev_tutorial{tutorial_discrete_fourier_transform} +@next_tutorial{tutorial_how_to_use_OpenCV_parallel_for_} @next_tutorial{tutorial_how_to_use_OpenCV_parallel_for_new} | | | diff --git a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown index ab24d27ab1..742e49d765 100644 --- a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown +++ b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown @@ -1,16 +1,18 @@ -How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_use_OpenCV_parallel_for_} +How to use the OpenCV parallel_for_ function to parallelize your code (Mandelbrot set example) {#tutorial_how_to_use_OpenCV_parallel_for_} ================================================================== @tableofcontents @prev_tutorial{tutorial_file_input_output_with_xml_yml} +@next_tutorial{tutorial_how_to_use_OpenCV_parallel_for_new} +@next_tutorial{tutorial_univ_intrin} | | | | -: | :- | | Compatibility | OpenCV >= 3.0 | -@note See also C++ lambda usage with parallel for in [tuturial](@ref tutorial_how_to_use_OpenCV_parallel_for_new). +@note See this [tuturial](@ref tutorial_how_to_use_OpenCV_parallel_for_new) for a `parallel_for_` usage applied to image convolution. Goal ---- @@ -26,17 +28,17 @@ Precondition ------------ The first precondition is to have OpenCV built with a parallel framework. -In OpenCV 3.2, the following parallel frameworks are available in that order: +In OpenCV 4, the following parallel frameworks are available in that order: + 1. Intel Threading Building Blocks (3rdparty library, should be explicitly enabled) -2. C= Parallel C/C++ Programming Language Extension (3rdparty library, should be explicitly enabled) -3. OpenMP (integrated to compiler, should be explicitly enabled) -4. APPLE GCD (system wide, used automatically (APPLE only)) -5. Windows RT concurrency (system wide, used automatically (Windows RT only)) -6. Windows concurrency (part of runtime, used automatically (Windows only - MSVC++ >= 10)) -7. Pthreads (if available) +2. OpenMP (integrated to compiler, should be explicitly enabled) +3. APPLE GCD (system wide, used automatically (APPLE only)) +4. Windows RT concurrency (system wide, used automatically (Windows RT only)) +5. Windows concurrency (part of runtime, used automatically (Windows only - MSVC++ >= 10)) +6. Pthreads (if available) As you can see, several parallel frameworks can be used in the OpenCV library. Some parallel libraries -are third party libraries and have to be explicitly built and enabled in CMake (e.g. TBB, C=), others are +are third party libraries and have to be explicitly built and enabled in CMake (e.g. TBB), others are automatically available with the platform (e.g. APPLE GCD) but chances are that you should be enable to have access to a parallel framework either directly or by enabling the option in CMake and rebuild the library. @@ -120,7 +122,7 @@ Escape time algorithm implementation @snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-escape-time-algorithm -Here, we used the [`std::complex`](http://en.cppreference.com/w/cpp/numeric/complex) template class to represent a +Here, we used the [`std::complex`](https://en.cppreference.com/cpp/numeric/complex) template class to represent a complex number. This function performs the test to check if the pixel is in set or not and returns the "escaped" iteration. Sequential Mandelbrot implementation @@ -143,7 +145,7 @@ Finally, to assign the grayscale value to the pixels, we use the following rule: Using a linear scale transformation is not enough to perceive the grayscale variation. To overcome this, we will boost the perception by using a square root scale transformation (borrowed from Jeremy D. Frens in his -[blog post](http://www.programming-during-recess.net/2016/06/26/color-schemes-for-mandelbrot-sets/)): +[blog post](https://web.archive.org/web/20250419124416/http://www.programming-during-recess.net/2016/06/26/color-schemes-for-mandelbrot-sets/)): \f$ f \left( x \right) = \sqrt{\frac{x}{\text{maxIter}}} \times 255 \f$ ![](images/how_to_use_OpenCV_parallel_for_sqrt_scale_transformation.png) @@ -179,7 +181,7 @@ or setting `nstripes=2` should be the same as by default it will use all the pro workload only on two threads. @note -C++ 11 standard allows to simplify the parallel implementation by get rid of the `ParallelMandelbrot` class and replacing it with lambda expression: +C++ 11 standard allows simplifying the parallel implementation by get rid of the `ParallelMandelbrot` class and replacing it with lambda expression: @snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11 diff --git a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown index 57cec4cba1..31dda1ab9a 100644 --- a/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown +++ b/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown @@ -1,9 +1,10 @@ -How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_use_OpenCV_parallel_for_new} +How to use the OpenCV parallel_for_ function to parallelize your code (convolution example) {#tutorial_how_to_use_OpenCV_parallel_for_new} ================================================================== @tableofcontents @prev_tutorial{tutorial_file_input_output_with_xml_yml} +@prev_tutorial{tutorial_how_to_use_OpenCV_parallel_for_} @next_tutorial{tutorial_univ_intrin} | | | @@ -122,7 +123,7 @@ For example, we can either To set the number of threads, you can use: @ref cv::setNumThreads. You can also specify the number of splitting using the nstripes parameter in @ref cv::parallel_for_. For instance, if your processor has 4 threads, setting `cv::setNumThreads(2)` or setting `nstripes=2` should be the same as by default it will use all the processor threads available but will split the workload only on two threads. -@note C++ 11 standard allows to simplify the parallel implementation by get rid of the `parallelConvolution` class and replacing it with lambda expression: +@note C++ 11 standard allows simplifying the parallel implementation by getting rid of the `parallelConvolution` class and replacing it with lambda expression: @snippet how_to_use_OpenCV_parallel_for_new.cpp convolution-parallel-cxx11 diff --git a/doc/tutorials/core/table_of_content_core.markdown b/doc/tutorials/core/table_of_content_core.markdown index 00f874edc0..2a5a4cbd08 100644 --- a/doc/tutorials/core/table_of_content_core.markdown +++ b/doc/tutorials/core/table_of_content_core.markdown @@ -14,5 +14,6 @@ The Core Functionality (core module) {#tutorial_table_of_content_core} ##### Advanced - @subpage tutorial_discrete_fourier_transform - @subpage tutorial_file_input_output_with_xml_yml +- @subpage tutorial_how_to_use_OpenCV_parallel_for_ - @subpage tutorial_how_to_use_OpenCV_parallel_for_new - @subpage tutorial_univ_intrin diff --git a/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown b/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown index 2023de809b..32388f6d9e 100644 --- a/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown +++ b/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.markdown @@ -26,7 +26,7 @@ Theory ------ @note The explanation below belongs to the book [Computer Vision: Algorithms and -Applications](http://szeliski.org/Book/) by Richard Szeliski and to *LearningOpenCV* +Applications](https://szeliski.org/Book/) by Richard Szeliski and to *LearningOpenCV* - *Smoothing*, also called *blurring*, is a simple and frequently used image processing operation.