![]() |
OpenCV
4.1.2
Open Source Computer Vision
|
In this tutorial you will learn how to use the 'dnn_superres' interface to upscale an image via pre-trained neural networks.
When building OpenCV, run the following command to build the 'dnn_superres' module:
Or make sure you check the dnn_superres module in the GUI version of CMake: cmake-gui.
Set header and namespaces
If you want you can set the namespace like the code above.
Create the Dnn Superres object
This is just to create the object, register the custom dnn layers and get access to the class functions.
Read the model
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
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
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'.
Original:
Upscaled Image via FSRCNN:
Upscaled Image via Bicubic Interpolation: