1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2025-02-05 09:28:27 +03:00
180 changed files with 11419 additions and 1819 deletions
+91
View File
@@ -0,0 +1,91 @@
Handling Animated Image Files {#tutorial_animations}
===========================
@tableofcontents
| | |
| -: | :- |
| Original author | Suleyman Turkmen (with help of ChatGPT) |
| Compatibility | OpenCV >= 4.11 |
Goal
----
In this tutorial, you will learn how to:
- Use `cv::imreadanimation` to load frames from animated image files.
- Understand the structure and parameters of the `cv::Animation` structure.
- Display individual frames from an animation.
- Use `cv::imwriteanimation` to write `cv::Animation` to a file.
Source Code
-----------
@add_toggle_cpp
- **Downloadable code**: Click
[here](https://github.com/opencv/opencv/tree/4.x/samples/cpp/tutorial_code/imgcodecs/animations.cpp)
- **Code at a glance:**
@include samples/cpp/tutorial_code/imgcodecs/animations.cpp
@end_toggle
@add_toggle_python
- **Downloadable code**: Click
[here](https://github.com/opencv/opencv/tree/4.x/samples/python/tutorial_code/imgcodecs/animations.py)
- **Code at a glance:**
@include samples/python/tutorial_code/imgcodecs/animations.py
@end_toggle
Explanation
-----------
## Initializing the Animation Structure
Initialize a `cv::Animation` structure to hold the frames from the animated image file.
@add_toggle_cpp
@snippet cpp/tutorial_code/imgcodecs/animations.cpp init_animation
@end_toggle
@add_toggle_python
@snippet python/tutorial_code/imgcodecs/animations.py init_animation
@end_toggle
## Loading Frames
Use `cv::imreadanimation` to load frames from the specified file. Here, we load all frames from an animated WebP image.
@add_toggle_cpp
@snippet cpp/tutorial_code/imgcodecs/animations.cpp read_animation
@end_toggle
@add_toggle_python
@snippet python/tutorial_code/imgcodecs/animations.py read_animation
@end_toggle
## Displaying Frames
Each frame in the `animation.frames` vector can be displayed as a standalone image. This loop iterates through each frame, displaying it in a window with a short delay to simulate the animation.
@add_toggle_cpp
@snippet cpp/tutorial_code/imgcodecs/animations.cpp show_animation
@end_toggle
@add_toggle_python
@snippet python/tutorial_code/imgcodecs/animations.py show_animation
@end_toggle
## Saving Animation
@add_toggle_cpp
@snippet cpp/tutorial_code/imgcodecs/animations.cpp write_animation
@end_toggle
@add_toggle_python
@snippet python/tutorial_code/imgcodecs/animations.py write_animation
@end_toggle
## Summary
The `cv::imreadanimation` and `cv::imwriteanimation` functions make it easy to work with animated image files by loading frames into a `cv::Animation` structure, allowing frame-by-frame processing.
With these functions, you can load, process, and save frames from animated image files like GIF, AVIF, APNG, and WebP.
@@ -10,3 +10,4 @@ Application utils (highgui, imgcodecs, videoio modules) {#tutorial_table_of_cont
- @subpage tutorial_orbbec_uvc
- @subpage tutorial_intelperc
- @subpage tutorial_wayland_ubuntu
- @subpage tutorial_animations
@@ -83,7 +83,7 @@ Arranging the terms: \f$r = x \cos \theta + y \sin \theta\f$
### Standard and Probabilistic Hough Line Transform
OpenCV implements two kind of Hough Line Transforms:
OpenCV implements three kind of Hough Line Transforms:
a. **The Standard Hough Transform**
@@ -97,6 +97,12 @@ b. **The Probabilistic Hough Line Transform**
of the detected lines \f$(x_{0}, y_{0}, x_{1}, y_{1})\f$
- In OpenCV it is implemented with the function **HoughLinesP()**
c. **The Weighted Hough Transform**
- Uses edge intensity instead binary 0 or 1 values in standard Hough transform.
- In OpenCV it is implemented with the function **HoughLines()** with use_edgeval=true.
- See the example in samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp.
### What does this program do?
- Loads an image
- Applies a *Standard Hough Line Transform* and a *Probabilistic Line Transform*.
@@ -217,7 +217,7 @@ Following options can be used to produce special builds with instrumentation or
| `ENABLE_BUILD_HARDENING` | GCC, Clang, MSVC | Enable compiler options which reduce possibility of code exploitation. |
| `ENABLE_LTO` | GCC, Clang, MSVC | Enable Link Time Optimization (LTO). |
| `ENABLE_THIN_LTO` | Clang | Enable thin LTO which incorporates intermediate bitcode to binaries allowing consumers optimize their applications later. |
| `OPENCV_ALGO_HINT_DEFAULT` | Any | Set default OpenCV implementation hint value: `ALGO_HINT_ACCURATE` or `ALGO_HINT_APROX`. Dangerous! The option changes behaviour globally and may affect accuracy of many algorithms. |
| `OPENCV_ALGO_HINT_DEFAULT` | Any | Set default OpenCV implementation hint value: `ALGO_HINT_ACCURATE` or `ALGO_HINT_APPROX`. Dangerous! The option changes behaviour globally and may affect accuracy of many algorithms. |
@see [GCC instrumentation](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html)
@see [Build hardening](https://en.wikipedia.org/wiki/Hardening_(computing))
@@ -310,11 +310,12 @@ Following formats can be read by OpenCV without help of any third-party library:
| [JPEG2000 with OpenJPEG](https://en.wikipedia.org/wiki/OpenJPEG) | `WITH_OPENJPEG` | _ON_ | `BUILD_OPENJPEG` |
| [JPEG2000 with JasPer](https://en.wikipedia.org/wiki/JasPer) | `WITH_JASPER` | _ON_ (see note) | `BUILD_JASPER` |
| [EXR](https://en.wikipedia.org/wiki/OpenEXR) | `WITH_OPENEXR` | _ON_ | `BUILD_OPENEXR` |
| [JPEG XL](https://en.wikipedia.org/wiki/JPEG_XL) | `WITH_JPEGXL` | _ON_ | Not supported. (see note) |
All libraries required to read images in these formats are included into OpenCV and will be built automatically if not found at the configuration stage. Corresponding `BUILD_*` options will force building and using own libraries, they are enabled by default on some platforms, e.g. Windows.
@note OpenJPEG have higher priority than JasPer which is deprecated. In order to use JasPer, OpenJPEG must be disabled.
@note (JPEG XL) OpenCV doesn't contain libjxl source code, so `BUILD_JPEGXL` is not supported.
### GDAL integration
@@ -9,41 +9,49 @@ Installation in MacOS {#tutorial_macos_install}
| Original author | `@sajarindider` |
| Compatibility | OpenCV >= 3.4 |
The following steps have been tested for MacOSX (Mavericks) but should work with other versions as well.
The following steps have been tested for macOS (Mavericks) but should work with other versions as well.
Required Packages
-----------------
- CMake 3.9 or higher
- Git
- Python 2.7 or later and Numpy 1.5 or later
- Python 3.x and NumPy 1.5 or later
This tutorial will assume you have [Python](https://docs.python.org/3/using/mac.html),
[Numpy](https://docs.scipy.org/doc/numpy-1.10.1/user/install.html) and
[Git](https://www.atlassian.com/git/tutorials/install-git) installed on your machine.
[NumPy](https://numpy.org/install/) and
[Git](https://git-scm.com/downloads/mac) installed on your machine.
@note
OSX comes with Python 2.7 by default, you will need to install Python 3.8 if you want to use it specifically.
- macOS up to 12.2 (Monterey): Comes with Python 2.7 pre-installed.
- macOS 12.3 and later: Python 2.7 has been removed, and no version of Python is included by default.
It is recommended to install the latest version of Python 3.x (at least Python 3.8) for compatibility with the latest OpenCV Python bindings.
@note
If you XCode and XCode Command Line-Tools installed, you already have git installed on your machine.
If you have Xcode and Xcode Command Line Tools installed, Git is already available on your machine.
Installing CMake
----------------
-# Find the version for your system and download CMake from their release's [page](https://cmake.org/download/)
-# Install the dmg package and launch it from Applications. That will give you the UI app of CMake
-# Install the `.dmg` package and launch it from Applications. That will give you the UI app of CMake
-# From the CMake app window, choose menu Tools --> How to Install For Command Line Use. Then, follow the instructions from the pop-up there.
-# Install folder will be /usr/bin/ by default, submit it by choosing Install command line links.
-# The install folder will be `/usr/local/bin/` by default. Complete the installation by choosing Install command line links.
-# Test that CMake is installed correctly by running:
-# Test that it works by running
@code{.bash}
cmake --version
@endcode
@note You can use [Homebrew](https://brew.sh/) to install CMake with @code{.bash} brew install cmake @endcode
@note You can use [Homebrew](https://brew.sh/) to install CMake with:
@code{.bash}
brew install cmake
@endcode
Getting OpenCV Source Code
--------------------------
@@ -53,20 +61,22 @@ You can use the latest stable OpenCV version or you can grab the latest snapshot
### Getting the Latest Stable OpenCV Version
- Go to our [downloads page](https://opencv.org/releases).
- Download the source archive and unpack it.
- Go to our [OpenCV releases page](https://opencv.org/releases).
- Download the source archive of the latest version (e.g., OpenCV 4.x) and unpack it.
### Getting the Cutting-edge OpenCV from the Git Repository
Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv).
If you need modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
Launch Git client and clone [OpenCV repository](https://github.com/opencv/opencv).
If you need modules from [OpenCV contrib repository](https://github.com/opencv/opencv_contrib) then clone it as well.
For example:
@code{.bash}
cd ~/<your_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
@endcode
For example
@code{.bash}
cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
@endcode
Building OpenCV from Source Using CMake
---------------------------------------
@@ -74,51 +84,96 @@ Building OpenCV from Source Using CMake
the generated Makefiles, project files as well the object files and output binaries and enter
there.
For example
For example:
@code{.bash}
mkdir build_opencv
cd build_opencv
@endcode
@note It is good practice to keep clean your source code directories. Create build directory outside of source tree.
@note It is good practice to keep your source code directories clean. Create the build directory outside of the source tree.
-# Configuring. Run `cmake [<some optional parameters>] <path to the OpenCV source directory>`
For example
For example:
@code{.bash}
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON ../opencv
@endcode
or cmake-gui
Alternatively, you can use the CMake GUI (`cmake-gui`):
- set the OpenCV source code path to, e.g. `/home/user/opencv`
- set the binary build path to your CMake build directory, e.g. `/home/user/build_opencv`
- set the OpenCV source code path to, e.g. `/Users/your_username/opencv`
- set the binary build path to your CMake build directory, e.g. `/Users/your_username/build_opencv`
- set optional parameters
- run: "Configure"
- run: "Generate"
-# Description of some parameters
- build type: `CMAKE_BUILD_TYPE=Release` (or `Debug`)
- to build with modules from opencv_contrib set `OPENCV_EXTRA_MODULES_PATH` to `<path to
opencv_contrib>/modules`
- set `BUILD_DOCS=ON` for building documents (doxygen is required)
- set `BUILD_EXAMPLES=ON` to build all examples
- build type: `-DCMAKE_BUILD_TYPE=Release` (or `Debug`).
- include Extra Modules: If you cloned the `opencv_contrib` repository and want to include its modules, set:
@code{.bash}
-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
@endcode
- set `-DBUILD_DOCS=ON` for building documents (doxygen is required)
- set `-DBUILD_EXAMPLES=ON` to build all examples
-# [optional] Building python. Set the following python parameters:
- `PYTHON3_EXECUTABLE = <path to python>`
- `PYTHON3_INCLUDE_DIR = /usr/include/python<version>`
- `PYTHON3_NUMPY_INCLUDE_DIRS =
/usr/lib/python<version>/dist-packages/numpy/core/include/`
- `-DPYTHON3_EXECUTABLE=$(which python3)`
- `-DPYTHON3_INCLUDE_DIR=$(python3 -c "from sysconfig import get_paths as gp; print(gp()['include'])")`
- `-DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())")`
-# Build. From build directory execute *make*, it is recommended to do this in several threads
For example
For example:
@code{.bash}
make -j7 # runs 7 jobs in parallel
make -j$(sysctl -n hw.ncpu) # runs the build using all available CPU cores
@endcode
-# To use OpenCV in your CMake-based projects through `find_package(OpenCV)` specify `OpenCV_DIR=<path_to_build_or_install_directory>` variable.
-# After building, you can install OpenCV system-wide using:
@code{.bash}
sudo make install
@endcode
-# To use OpenCV in your CMake-based projects through `find_package(OpenCV)`, specify the `OpenCV_DIR` variable pointing to the build or install directory.
For example:
@code{.bash}
cmake -DOpenCV_DIR=~/build_opencv ..
@endcode
### Verifying the OpenCV Installation
After building (and optionally installing) OpenCV, you can verify the installation by checking the version using Python:
@code{.bash}
python3 -c "import cv2; print(cv2.__version__)"
@endcode
This command should output the version of OpenCV you have installed.
@note
You can also use a package manager like [Homebrew](https://brew.sh/)
or [pip](https://pip.pypa.io/en/stable/) to install releases of OpenCV only (Not the cutting edge).
- Installing via Homebrew:
For example:
@code{.bash}
brew install opencv
@endcode
- Installing via pip:
For example:
@code{.bash}
pip install opencv-python
@endcode
@note To access the extra modules from `opencv_contrib`, install the `opencv-contrib-python` package using `pip install opencv-contrib-python`.