mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
+11
-8
@@ -9,6 +9,9 @@ How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_u
|
||||
| -: | :- |
|
||||
| Compatibility | OpenCV >= 3.0 |
|
||||
|
||||
|
||||
@note See also C++ lambda usage with parallel for in [tuturial](@ref tutorial_how_to_use_OpenCV_parallel_for_new).
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
@@ -20,7 +23,7 @@ If you want more information about multithreading, you will have to refer to a r
|
||||
to remain simple.
|
||||
|
||||
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:
|
||||
@@ -50,7 +53,7 @@ We will use the example of drawing a Mandelbrot set to show how from a regular s
|
||||
the code to parallelize the computation.
|
||||
|
||||
Theory
|
||||
-----------
|
||||
------
|
||||
|
||||
The Mandelbrot set definition has been named in tribute to the mathematician Benoit Mandelbrot by the mathematician
|
||||
Adrien Douady. It has been famous outside of the mathematics field as the image representation is an example of a
|
||||
@@ -69,7 +72,7 @@ Here, we will just introduce the formula to draw the Mandelbrot set (from the me
|
||||
> \f[\limsup_{n\to\infty}|z_{n+1}|\leqslant2\f]
|
||||
|
||||
Pseudocode
|
||||
-----------
|
||||
----------
|
||||
|
||||
A simple algorithm to generate a representation of the Mandelbrot set is called the
|
||||
["escape time algorithm"](https://en.wikipedia.org/wiki/Mandelbrot_set#Escape_time_algorithm).
|
||||
@@ -110,10 +113,10 @@ On this figure, we recall that the real part of a complex number is on the x-axi
|
||||
You can see that the whole shape can be repeatedly visible if we zoom at particular locations.
|
||||
|
||||
Implementation
|
||||
-----------
|
||||
--------------
|
||||
|
||||
Escape time algorithm implementation
|
||||
--------------------------
|
||||
------------------------------------
|
||||
|
||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-escape-time-algorithm
|
||||
|
||||
@@ -121,7 +124,7 @@ Here, we used the [`std::complex`](http://en.cppreference.com/w/cpp/numeric/comp
|
||||
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
|
||||
--------------------------
|
||||
------------------------------------
|
||||
|
||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-sequential
|
||||
|
||||
@@ -149,7 +152,7 @@ The green curve corresponds to a simple linear scale transformation, the blue on
|
||||
and you can observe how the lowest values will be boosted when looking at the slope at these positions.
|
||||
|
||||
Parallel Mandelbrot implementation
|
||||
--------------------------
|
||||
----------------------------------
|
||||
|
||||
When looking at the sequential implementation, we can notice that each pixel is computed independently. To optimize the
|
||||
computation, we can perform multiple pixel calculations in parallel, by exploiting the multi-core architecture of modern
|
||||
@@ -181,7 +184,7 @@ C++ 11 standard allows to simplify the parallel implementation by get rid of the
|
||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11
|
||||
|
||||
Results
|
||||
-----------
|
||||
-------
|
||||
|
||||
You can find the full tutorial code [here](https://github.com/opencv/opencv/blob/5.x/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp).
|
||||
The performance of the parallel implementation depends of the type of CPU you have. For instance, on 4 cores / 8 threads
|
||||
|
||||
@@ -18,7 +18,7 @@ This tutorial assumes you have the following installed and configured:
|
||||
- Android Studio
|
||||
- JDK
|
||||
- Android SDK and NDK
|
||||
- OpenCV for Android SDK from official [release page on Github](https://github.com/opencv/opencv/releases)
|
||||
- Optional: OpenCV for Android SDK from official [release page on Github](https://github.com/opencv/opencv/releases)
|
||||
or [SourceForge](https://sourceforge.net/projects/opencvlibrary/). Advanced: as alternative the SDK may be
|
||||
built from source code by [instruction on wiki](https://github.com/opencv/opencv/wiki/Custom-OpenCV-Android-SDK-and-AAR-package-build).
|
||||
|
||||
@@ -26,8 +26,9 @@ If you need help with anything of the above, you may refer to our @ref tutorial_
|
||||
|
||||
If you encounter any error after thoroughly following these steps, feel free to contact us via OpenCV [forum](https://forum.opencv.org). We'll do our best to help you out.
|
||||
|
||||
Hello OpenCV sample
|
||||
-------------------
|
||||
|
||||
Hello OpenCV sample with SDK
|
||||
----------------------------
|
||||
|
||||
In this section we're gonna create a simple app that does nothing but OpenCV loading. In next section we'll extend it to support camera.
|
||||
|
||||
@@ -75,11 +76,10 @@ In addition to this instruction you can use some video guide, for example [this
|
||||
@endcode
|
||||
The fix was found [here](https://stackoverflow.com/questions/73225714/import-opencv-sdk-to-android-studio-chipmunk)
|
||||
|
||||
6. OpenCV project uses `aidl` and `buildConfig` features. Please enable them in
|
||||
6. OpenCV project uses `buildConfig` feature. Please enable it in
|
||||
`MyApplication/OpenCV/build.gradle` file to `android` block:
|
||||
@code{.gradle}
|
||||
buildFeatures{
|
||||
aidl true
|
||||
buildConfig true
|
||||
}
|
||||
|
||||
@@ -115,6 +115,43 @@ In addition to this instruction you can use some video guide, for example [this
|
||||
|
||||

|
||||
|
||||
Hello OpenCV sample with Maven Central
|
||||
--------------------------------------
|
||||
|
||||
Since OpenCV 4.9.0 OpenCV for Android package is available with Maven Central and may be installed
|
||||
automatically as Gradle dependency. In this section we're gonna create a simple app that does nothing
|
||||
but OpenCV loading with Maven Central.
|
||||
|
||||
1. Open Android Studio and create empty project by choosing ***Empty Views Activity***
|
||||
|
||||

|
||||
|
||||
2. Setup the project:
|
||||
- Choose ***Java*** language
|
||||
- Choose ***Groovy DSL*** build configuration language
|
||||
- Choose ***Minumum SDK*** with the version number not less than OpenCV supports. For 4.9.0 minimal SDK version is 21.
|
||||
|
||||

|
||||
|
||||
3. Edit `build.gradle` and add OpenCV library to Dependencies list like this:
|
||||
@code{.gradle}
|
||||
dependencies {
|
||||
implementation 'org.opencv:opencv:4.9.0'
|
||||
}
|
||||
@endcode
|
||||
`4.9.0` may be replaced by any version available as [official release](https://central.sonatype.com/artifact/org.opencv/opencv).
|
||||
|
||||
4. Before using any OpenCV function you have to load the library first. If you application includes other
|
||||
OpenCV-dependent native libraries you should load them ***after*** OpenCV initialization. Add the folowing
|
||||
code to load the library at app start:
|
||||
@snippet samples/android/tutorial-1-camerapreview/src/org/opencv/samples/tutorial1/Tutorial1Activity.java ocv_loader_init
|
||||
Like this:
|
||||

|
||||
|
||||
5. Choose a device to check the sample on and run the code by pressing `run` button
|
||||
|
||||

|
||||
|
||||
Camera view sample
|
||||
------------------
|
||||
|
||||
|
||||
@@ -378,6 +378,9 @@ our OpenCV library that we use in our projects. Start up a command window and en
|
||||
|
||||
setx OpenCV_DIR D:\OpenCV\build\x64\vc16 (suggested for Visual Studio 2019 - 64 bit Windows)
|
||||
setx OpenCV_DIR D:\OpenCV\build\x86\vc16 (suggested for Visual Studio 2019 - 32 bit Windows)
|
||||
|
||||
setx OpenCV_DIR D:\OpenCV\build\x64\vc17 (suggested for Visual Studio 2022 - 64 bit Windows)
|
||||
setx OpenCV_DIR D:\OpenCV\build\x86\vc17 (suggested for Visual Studio 2022 - 32 bit Windows)
|
||||
@endcode
|
||||
Here the directory is where you have your OpenCV binaries (*extracted* or *built*). You can have
|
||||
different platform (e.g. x64 instead of x86) or compiler type, so substitute appropriate value.
|
||||
|
||||
Reference in New Issue
Block a user