vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,132 @@
|
||||
Super-resolution benchmarking {#tutorial_dnn_superres_benchmark}
|
||||
===========================
|
||||
|
||||
Benchmarking
|
||||
----
|
||||
|
||||
The super-resolution module contains sample codes for benchmarking, in order to compare different models and algorithms.
|
||||
Here is presented a sample code for performing benchmarking, and then a few benchmarking results are collected.
|
||||
It was performed on an Intel i7-9700K CPU on an Ubuntu 18.04.02 OS.
|
||||
|
||||
Source Code of the sample
|
||||
-----------
|
||||
|
||||
@includelineno dnn_superres/samples/dnn_superres_benchmark_quality.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# **Read and downscale the image**
|
||||
@code{.cpp}
|
||||
int width = img.cols - (img.cols % scale);
|
||||
int height = img.rows - (img.rows % scale);
|
||||
Mat cropped = img(Rect(0, 0, width, height));
|
||||
Mat img_downscaled;
|
||||
cv::resize(cropped, img_downscaled, cv::Size(), 1.0 / scale, 1.0 / scale);
|
||||
@endcode
|
||||
|
||||
Resize the image by the scaling factor. Before that a cropping is necessary, so the images will align.
|
||||
|
||||
-# **Set the model**
|
||||
@code{.cpp}
|
||||
DnnSuperResImpl sr;
|
||||
sr.readModel(path);
|
||||
sr.setModel(algorithm, scale);
|
||||
sr.upsample(img_downscaled, img_new);
|
||||
@endcode
|
||||
|
||||
Instantiate a dnn super-resolution object. Read and set the algorithm and scaling factor.
|
||||
|
||||
-# **Perform benchmarking**
|
||||
@code{.cpp}
|
||||
double psnr = PSNR(img_new, cropped);
|
||||
Scalar q = cv::quality::QualitySSIM::compute(img_new, cropped, cv::noArray());
|
||||
double ssim = mean(cv::Vec3f(q[0], q[1], q[2]))[0];
|
||||
@endcode
|
||||
|
||||
Calculate PSNR and SSIM. Use OpenCVs PSNR (core opencv) and SSIM (contrib) functions to compare the images.
|
||||
Repeat it with other upscaling algorithms, such as other DL models or interpolation methods (eg. bicubic, nearest neighbor).
|
||||
|
||||
Benchmarking results
|
||||
-----------
|
||||
|
||||
## General100 dataset
|
||||
|
||||
### 2x scaling factor
|
||||
|
||||
|
||||
| | Avg inference time in sec (CPU)| Avg PSNR | Avg SSIM |
|
||||
| ------------- |:-------------------:| ---------:|--------:|
|
||||
| ESPCN | **0.008795** | 32.7059 | 0.9276 |
|
||||
| EDSR | 5.923450 | **34.1300** | **0.9447** |
|
||||
| FSRCNN | 0.021741 | 32.8886 | 0.9301 |
|
||||
| LapSRN | 0.114812 | 32.2681 | 0.9248 |
|
||||
| Bicubic | 0.000208 | 32.1638 | 0.9305 |
|
||||
| Nearest neighbor | 0.000114 | 29.1665 | 0.9049 |
|
||||
| Lanczos | 0.001094 | 32.4687 | 0.9327 |
|
||||
|
||||
### 3x scaling factor
|
||||
|
||||
| | Avg inference time in sec (CPU)| Avg PSNR | Avg SSIM |
|
||||
| ------------- |:-------------------:| ---------:|--------:|
|
||||
| ESPCN | **0.005495** | 28.4229 | 0.8474 |
|
||||
| EDSR | 2.455510 | **29.9828** | **0.8801** |
|
||||
| FSRCNN | 0.008807 | 28.3068 | 0.8429 |
|
||||
| LapSRN | 0.282575 |26.7330 |0.8862 |
|
||||
| Bicubic | 0.000311 |26.0635 |0.8754 |
|
||||
| Nearest neighbor | 0.000148 |23.5628 |0.8174 |
|
||||
| Lanczos | 0.001012 |25.9115 |0.8706 |
|
||||
|
||||
|
||||
### 4x scaling factor
|
||||
|
||||
| | Avg inference time in sec (CPU)| Avg PSNR | Avg SSIM |
|
||||
| ------------- |:-------------------:| ---------:|--------:|
|
||||
| ESPCN | **0.004311** | 26.6870 | 0.7891 |
|
||||
| EDSR | 1.607570 | **28.1552** | **0.8317** |
|
||||
| FSRCNN | 0.005302 | 26.6088 | 0.7863 |
|
||||
| LapSRN | 0.121229 |26.7383 |0.7896 |
|
||||
| Bicubic | 0.000311 |26.0635 |0.8754 |
|
||||
| Nearest neighbor | 0.000148 |23.5628 |0.8174 |
|
||||
| Lanczos | 0.001012 |25.9115 |0.8706 |
|
||||
|
||||
|
||||
|
||||
## Images
|
||||
|
||||
### 2x scaling factor
|
||||
|
||||
|Set5: butterfly.png | size: 256x256 | ||
|
||||
|:-------------:|:-------------------:|:-------------:|:----:|
|
||||
|||| |
|
||||
|PSRN / SSIM / Speed (CPU)|26.6645 / 0.9048 / 0.000201 |23.6854 / 0.8698 / **0.000075** | **26.9476** / **0.9075** / 0.001039|
|
||||
|  |  | 
|
||||
|29.0341 / 0.9354 / **0.004157**| 29.0077 / 0.9345 / 0.006325 | 27.8212 / 0.9230 / 0.037937 | **30.0347** / **0.9453** / 2.077280 |
|
||||
|
||||
### 3x scaling factor
|
||||
|
||||
|Urban100: img_001.png | size: 1024x644 | ||
|
||||
|:-------------:|:-------------------:|:-------------:|:----:|
|
||||
|||| |
|
||||
|PSRN / SSIM / Speed (CPU)| 27.0474 / **0.8484** / 0.000391 | 26.0842 / 0.8353 / **0.000236** | **27.0704** / 0.8483 / 0.002234|
|
||||
||  | LapSRN is not trained for 3x <br/> because of its architecture | 
|
||||
|28.0118 / 0.8588 / **0.030748**| 28.0184 / 0.8597 / 0.094173 | | **30.5671** / **0.9019** / 9.517580 |
|
||||
|
||||
|
||||
### 4x scaling factor
|
||||
|
||||
|Set14: comic.png | size: 250x361 | ||
|
||||
|:-------------:|:-------------------:|:-------------:|:----:|
|
||||
|||| |
|
||||
|PSRN / SSIM / Speed (CPU)| **19.6766** / **0.6413** / 0.000262 |18.5106 / 0.5879 / **0.000085** | 19.4948 / 0.6317 / 0.001098|
|
||||
||  |  | 
|
||||
|20.0417 / 0.6302 / **0.001894**| 20.0885 / 0.6384 / 0.002103 | 20.0676 / 0.6339 / 0.061640 | **20.5233** / **0.6901** / 0.665876 |
|
||||
|
||||
### 8x scaling factor
|
||||
|
||||
|Div2K: 0006.png | size: 1356x2040 | |
|
||||
|:-------------:|:-------------------:|:-------------:|
|
||||
||||
|
||||
|PSRN / SSIM / Speed (CPU)| 26.3139 / **0.8033** / 0.001107| 23.8291 / 0.7340 / **0.000611** |
|
||||
||  | |
|
||||
|26.1565 / 0.7962 / 0.004782| **26.7046** / 0.7987 / 2.274290 | |
|
||||
@@ -0,0 +1,26 @@
|
||||
Super Resolution using CNNs {#tutorial_table_of_content_dnn_superres}
|
||||
===========================
|
||||
|
||||
- @subpage tutorial_dnn_superres_upscale_image_single
|
||||
|
||||
*Author:* Xavier Weber
|
||||
|
||||
How to upscale images using the 'dnn_superres' interface: single-output
|
||||
|
||||
- @subpage tutorial_dnn_superres_upscale_image_multi
|
||||
|
||||
*Author:* Fanny Monori
|
||||
|
||||
How to upscale images using the 'dnn_superres' interface: multi-output
|
||||
|
||||
- @subpage tutorial_dnn_superres_upscale_video
|
||||
|
||||
*Author:* Fanny Monori
|
||||
|
||||
How to upscale a video using the 'dnn_superres' interface.
|
||||
|
||||
- @subpage tutorial_dnn_superres_benchmark
|
||||
|
||||
*Authors:* Fanny Monori & Xavier Weber
|
||||
|
||||
Benchmarking of the algorithms.
|
||||
@@ -0,0 +1,91 @@
|
||||
Upscaling images: multi-output {#tutorial_dnn_superres_upscale_image_multi}
|
||||
===========================
|
||||
|
||||
In this tutorial you will learn how to use the 'dnn_superres' interface to upscale an image via a multi-output pre-trained neural network.
|
||||
OpenCVs dnn module supports accessing multiple nodes in one inference, if the names of the nodes are given.
|
||||
Currently there is one model included that is capable of giving more output in one inference run, that is the LapSRN model.
|
||||
LapSRN supports multiple outputs with one forward pass. It can now support 2x, 4x, 8x, and (2x, 4x) and (2x, 4x, 8x) super-resolution.
|
||||
The uploaded trained model files have the following output node names:
|
||||
- 2x model: NCHW_output
|
||||
- 4x model: NCHW_output_2x, NCHW_output_4x
|
||||
- 8x model: NCHW_output_2x, NCHW_output_4x, NCHW_output_8x
|
||||
|
||||
Building
|
||||
----
|
||||
|
||||
When building OpenCV, run the following command to build all the contrib module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/
|
||||
```
|
||||
|
||||
Or only build the dnn_superres module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/dnn_superres
|
||||
```
|
||||
|
||||
Or make sure you check the dnn_superres module in the GUI version of CMake: cmake-gui.
|
||||
|
||||
Source Code of the sample
|
||||
-----------
|
||||
|
||||
Run the sample code with the following command
|
||||
|
||||
```run
|
||||
./bin/example_dnn_superres_dnn_superres_multioutput path/to/image.png 2,4 NCHW_output_2x,NCHW_output_4x \
|
||||
path/to/opencv_contrib/modules/dnn_superres/models/LapSRN_x4.pb
|
||||
```
|
||||
|
||||
|
||||
@includelineno dnn_superres/samples/dnn_superres_multioutput.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# **Set header and namespaces**
|
||||
@code{.cpp}
|
||||
#include <opencv2/dnn_superres.hpp>
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace dnn_superres;
|
||||
@endcode
|
||||
|
||||
-# **Create the Dnn Superres object**
|
||||
@code{.cpp}
|
||||
DnnSuperResImpl sr;
|
||||
@endcode
|
||||
|
||||
Instantiate a dnn super-resolution object.
|
||||
|
||||
-# **Read the model**
|
||||
@code{.cpp}
|
||||
path = "models/LapSRN_x8.pb"
|
||||
sr.readModel(path);
|
||||
@endcode
|
||||
|
||||
Read the model from the given path.
|
||||
|
||||
-# **Set the model**
|
||||
@code{.cpp}
|
||||
sr.setModel("lapsrn", 8);
|
||||
@endcode
|
||||
|
||||
Sets the algorithm and scaling factor. The last (largest) scaling factor should be given here.
|
||||
|
||||
-# **Give the node names and scaling factors**
|
||||
@code{.cpp}
|
||||
std::vector<int> scales{2, 4, 8}
|
||||
std::vector<int> node_names{'NCHW_output_2x','NCHW_output_4x','NCHW_output_8x'}
|
||||
@endcode
|
||||
|
||||
Set the scaling factors, and the output node names in the model.
|
||||
|
||||
-# **Upscale an image**
|
||||
@code{.cpp}
|
||||
Mat img = cv::imread(img_path);
|
||||
std::vector<Mat> outputs;
|
||||
sr.upsampleMultioutput(img, outputs, scales, node_names);
|
||||
@endcode
|
||||
|
||||
Run the inference. The output images will be stored in a Mat vector.
|
||||
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,111 @@
|
||||
Upscaling images: single-output {#tutorial_dnn_superres_upscale_image_single}
|
||||
===========================
|
||||
|
||||
In this tutorial you will learn how to use the 'dnn_superres' interface to upscale an image via pre-trained neural networks. It works in C++ and Python.
|
||||
|
||||
Building
|
||||
----
|
||||
|
||||
When building OpenCV, run the following command to build all the contrib module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/
|
||||
```
|
||||
|
||||
Or only build the dnn_superres module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/dnn_superres
|
||||
```
|
||||
|
||||
Or make sure you check the dnn_superres module in the GUI version of CMake: cmake-gui.
|
||||
|
||||
Source Code of the sample
|
||||
-----------
|
||||
|
||||
You can run the sample code by doing
|
||||
|
||||
```run
|
||||
<path_of_your_opencv_build_directory>/bin/example_dnn_superres_dnn_superres <path_to_image.png> <algo_string> <upscale_int> <model_path.pb>
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```run
|
||||
/home/opencv/build/bin/example_dnn_superres_dnn_superres /home/image.png edsr 2 /home/EDSR_x2.pb
|
||||
```
|
||||
|
||||
@includelineno dnn_superres/samples/dnn_superres.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# **Set header and namespaces**
|
||||
@code{.cpp}
|
||||
#include <opencv2/dnn_superres.hpp>
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace dnn;
|
||||
using namespace dnn_superres;
|
||||
@endcode
|
||||
|
||||
If you want you can set the namespace like the code above.
|
||||
-# **Create the Dnn Superres object**
|
||||
@code{.cpp}
|
||||
DnnSuperResImpl sr;
|
||||
@endcode
|
||||
|
||||
This is just to create the object, register the custom dnn layers and get access to the class functions.
|
||||
-# **Read the model**
|
||||
@code{.cpp}
|
||||
path = "models/FSRCNN_x2.pb"
|
||||
sr.readModel(path);
|
||||
@endcode
|
||||
|
||||
This reads the TensorFlow model from the .pb file. Here 'path' is one of the pre-trained Tensorflow models' path file. You can download the models from OpenCV's GitHub, in the 'dnn_superres' module.
|
||||
-# **Set the model**
|
||||
@code{.cpp}
|
||||
sr.setModel("fsrcnn", 2);
|
||||
@endcode
|
||||
|
||||
Depending on the model you want to run, you have to set the algorithm and upscale factor. This is to know the desired algorithm and scale, even if you change the .pb file's name. For example: if you chose FSRCNN_x2.pb, your algorithm and scale will be 'fsrcnn' and 2, respectively. (Other algorithm options include "edsr", "espcn" and "lapsrn".)
|
||||
-# **Upscale an image**
|
||||
@code{.cpp}
|
||||
Mat img = cv::imread(img_path);
|
||||
Mat img_new;
|
||||
sr.upsample(img, img_new);
|
||||
@endcode
|
||||
|
||||
Now we can upscale any image. Load an image via the standard 'imread' function and create a new Mat for the destination image. Then simple
|
||||
upscale. Your upscaled image is located in 'img_new'.
|
||||
|
||||
An example in python
|
||||
-----------
|
||||
@code{.py}
|
||||
import cv2
|
||||
from cv2 import dnn_superres
|
||||
|
||||
# Create an SR object - only function that differs from c++ code
|
||||
sr = dnn_superres.DnnSuperResImpl_create()
|
||||
|
||||
# Read image
|
||||
image = cv2.imread('./image.png')
|
||||
|
||||
# Read the desired model
|
||||
path = "EDSR_x4.pb"
|
||||
sr.readModel(path)
|
||||
|
||||
# Set the desired model and scale to get correct pre- and post-processing
|
||||
sr.setModel("edsr", 4)
|
||||
|
||||
# Upscale the image
|
||||
result = sr.upsample(image)
|
||||
|
||||
# Save the image
|
||||
cv2.imwrite("./upscaled.png", result)
|
||||
@endcode
|
||||
|
||||
|
||||
Original: 
|
||||
Upscaled Image via FSRCNN: 
|
||||
Upscaled Image via Bicubic Interpolation: 
|
||||
@@ -0,0 +1,62 @@
|
||||
Upscaling video {#tutorial_dnn_superres_upscale_video}
|
||||
===========================
|
||||
|
||||
In this tutorial you will learn how to use the 'dnn_superres' interface to upscale video via pre-trained neural networks.
|
||||
|
||||
Building
|
||||
----
|
||||
|
||||
When building OpenCV, run the following command to build all the contrib module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/
|
||||
```
|
||||
|
||||
Or only build the dnn_superres module:
|
||||
|
||||
```make
|
||||
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/dnn_superres
|
||||
```
|
||||
|
||||
Or make sure you check the dnn_superres module in the GUI version of CMake: cmake-gui.
|
||||
|
||||
Source Code of the sample
|
||||
-----------
|
||||
|
||||
@includelineno dnn_superres/samples/dnn_superres_video.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# **Set header and namespaces**
|
||||
@code{.cpp}
|
||||
#include <opencv2/dnn_superres.hpp>
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace dnn_superres;
|
||||
@endcode
|
||||
-# **Create the Dnn Superres object**
|
||||
@code{.cpp}
|
||||
DnnSuperResImpl sr;
|
||||
@endcode
|
||||
Instantiate a dnn super-resolution object.
|
||||
-# **Read the model**
|
||||
@code{.cpp}
|
||||
path = "models/ESPCN_x2.pb"
|
||||
sr.readModel(path);
|
||||
sr.setModel("espcn", 2);
|
||||
@endcode
|
||||
Read the model from the given path and sets the algorithm and scaling factor.
|
||||
-# **Upscale a video**
|
||||
@code{.cpp}
|
||||
for(;;)
|
||||
{
|
||||
Mat frame, output_frame;
|
||||
input_video >> frame;
|
||||
if ( frame.empty() )
|
||||
break;
|
||||
sr.upsample(frame, output_frame);
|
||||
...
|
||||
}
|
||||
@endcode
|
||||
Process and upsample video frame by frame.
|
||||