vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:11:13 +08:00
commit 12022378a3
3872 changed files with 2513409 additions and 0 deletions
@@ -0,0 +1,77 @@
Image Inpainting {#tutorial_xphoto_inpainting}
================
Introduction
------------
In this tutorial we will show how to use the algorithm Rapid Frequency Selective Reconstructiom (FSR) for image inpainting.
Basics
------
Image Inpainting is the process of reconstructing damaged or missing parts of an image.
This is achieved by replacing distorted pixels by pixels similar to the neighboring ones. There are several algorithms for inpainting, using different approaches for such replacement.
One of those algorithms is called **Rapid Frequency Selectice Reconstruction (FSR)**.
FSR reconstructs image signals by exploiting the property that small areas of images can be represented sparsely in the Fourier domain. See @cite GenserPCS2018 and @cite SeilerTIP2015 for details.
FSR can be utilized for the following areas of application:
-# **Error Concealment (Inpainting)**:
The sampling mask indicates the missing pixels of the distorted input image to be reconstructed.
-# **Non-Regular Sampling**:
For more information on how to choose a good sampling mask, please review @cite GroscheICIP2018 and @cite GroscheIST2018.
Example
-------
The following sample code shows how to use FSR for inpainting.
The non-zero pixels of the error mask indicate valid image area, while zero pixels indicate area to be reconstructed.
You can create an arbitrary mask manually using tools like Paint or GIMP. Start with a plain white image and draw some distortions in black.
@code{.cpp}
#include <opencv2/opencv.hpp>
#include <opencv2/xphoto/inpainting.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char** argv)
{
// read image and error pattern
Mat original_, mask_;
original_ = imread("images/kodim22.png");
mask_ = imread("images/pattern_random.png", IMREAD_GRAYSCALE);
// make sure that mask and source image have the same size
Mat mask;
resize(mask_, mask, original_.size(), 0.0, 0.0, cv::INTER_NEAREST);
// distort image
Mat im_distorted(original_.size(), original_.type(), Scalar::all(0));
original_.copyTo(im_distorted, mask); // copy valid pixels only (i.e. non-zero pixels in mask)
// reconstruct the distorted image
// choose quality profile fast (xphoto::INPAINT_FSR_FAST) or best (xphoto::INPAINT_FSR_BEST)
Mat reconstructed;
xphoto::inpaint(im_distorted, mask, reconstructed, xphoto::INPAINT_FSR_FAST);
imshow("orignal image", original_);
imshow("distorted image", im_distorted);
imshow("reconstructed image", reconstructed);
waitKey();
return 0;
}
@endcode
Original and distorted image:
![image](images/originalVSdistorted.jpg)
Reconstruction:
![image](images/reconstructed_fastVSbest.jpg)
Left image: fast quality profile (run time 8 seconds). Right image: best quality profile (1 minute 51 seconds).
Additional Resources
--------------------
[Comparison of FSR to existing inpainting methods in OpenCV](https://github.com/opencv/opencv_contrib/files/3730212/inpainting_comparison.pdf)
Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

@@ -0,0 +1,23 @@
Oil painting effect {#tutorial_xphoto_oil_painting_effect}
===================================================
Introduction
------------
Image is converted in a color space default color space COLOR_BGR2GRAY.
For every pixel in the image a program calculated a histogram (first plane of color space) of the neighbouring of size 2*size+1.
and assigned the value of the most frequently occurring value. The result looks almost like an oil painting. Parameter 4 of oilPainting is used to decrease image dynamic and hence increase oil painting effect.
Example
--------------------
@code{.cpp}
Mat img;
Mat dst;
img = imread("opencv/samples/data/baboon.jpg");
xphoto::oilPainting(img, dst, 10, 1, COLOR_BGR2Lab);
imshow("oil painting effect", dst);
@endcode
Original ![](images/baboon.jpg)
Oil painting effect ![](images/baboon_oil_painting_effect.jpg)
@@ -0,0 +1,42 @@
Training the learning-based white balance algorithm {#tutorial_xphoto_training_white_balance}
===================================================
Introduction
------------
Many traditional white balance algorithms are statistics-based, i.e. they rely on the fact that certain assumptions should hold in properly white-balanced images
like the well-known grey-world assumption. However, better results can often be achieved by leveraging large datasets of images with ground-truth
illuminants in a learning-based framework. This tutorial demonstrates how to train a learning-based white balance algorithm and evaluate the quality of the results.
How to train a model
--------------------
-# Download a dataset for training. In this tutorial we will use the [Gehler-Shi dataset ](http://www.cs.sfu.ca/~colour/data/shi_gehler/). Extract all 568 training images
in one folder. A file containing ground-truth illuminant values (real_illum_568..mat) is downloaded separately.
-# We will be using a [Python script ](https://github.com/opencv/opencv_contrib/tree/master/modules/xphoto/samples/learn_color_balance.py) for training.
Call it with the following parameters:
@code
python learn_color_balance.py -i <path to the folder with training images> -g <path to real_illum_568..mat> -r 0,378 --num_trees 30 --max_tree_depth 6 --num_augmented 0
@endcode
This should start training a model on the first 378 images (2/3 of the whole dataset). We set the size of the model to be 30 regression tree pairs per feature and limit
the tree depth to be no more then 6. By default the resulting model will be saved to color_balance_model.yml
-# Use the trained model by passing its path when constructing an instance of LearningBasedWB:
@code{.cpp}
Ptr<xphoto::LearningBasedWB> wb = xphoto::createLearningBasedWB(modelFilename);
@endcode
How to evaluate a model
----------------------
-# We will use a [benchmarking script ](https://github.com/opencv/opencv_contrib/tree/master/modules/xphoto/samples/color_balance_benchmark.py) to compare
the model that we've trained with the classic grey-world algorithm on the remaining 1/3 of the dataset. Call the script with the following parameters:
@code
python color_balance_benchmark.py -a grayworld,learning_based:color_balance_model.yml -m <full path to folder containing the model> -i <path to the folder with training images> -g <path to real_illum_568..mat> -r 379,567 -d "img"
@endcode
-# The objective evaluation results are stored in white_balance_eval_result.html and the resulting white-balanced images are stored in the img folder for a qualitative
comparison of algorithms. Different algorithms are compared in terms of angular error between the estimated and ground-truth illuminants.