In this tutorial you will learn how to use the 'dnn_superres' interface to upscale video via pre-trained neural networks.
Or make sure you check the dnn_superres module in the GUI version of CMake: cmake-gui.
1
2
3
4
5#include <iostream>
6
8
11
15
16int main(
int argc,
char *argv[])
17{
18
19
20 if (argc < 4) {
21 cout << "usage: Arg 1: input video path" << endl;
22 cout << "\t Arg 2: output video path" << endl;
23 cout << "\t Arg 3: algorithm | edsr, espcn, fsrcnn or lapsrn" << endl;
24 cout << "\t Arg 4: scale | 2, 3, 4 or 8 \n";
25 cout << "\t Arg 5: path to model file \n";
26 return -1;
27 }
28
29 string input_path = string(argv[1]);
30 string output_path = string(argv[2]);
31 string algorithm = string(argv[3]);
32 int scale = atoi(argv[4]);
33 string path = string(argv[5]);
34
39
42
43 if (!input_video.isOpened())
44 {
45 std::cerr << "Could not open the video." << std::endl;
46 return -1;
47 }
48
49 DnnSuperResImpl sr;
50 sr.readModel(path);
51 sr.setModel(algorithm, scale);
52
53 for(;;)
54 {
55 Mat frame, output_frame;
56 input_video >> frame;
57
59 break;
60
61 sr.upsample(frame, output_frame);
62 output_video << output_frame;
63
65 imshow(
"Upsampled video", output_frame);
66
68 imshow(
"Original video", frame);
69
71 if(c==27)
72 break;
73 }
74
75 input_video.release();
77
78 return 0;
79}
n-dimensional dense array class
Definition mat.hpp:812
bool empty() const
Returns true if the array has no elements.
Class for video capturing from video files, image sequences or cameras.
Definition videoio.hpp:731
Video writer class.
Definition videoio.hpp:1009
virtual bool open(const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)
Initializes or reinitializes video writer.
virtual void release()
Closes the video writer.
Size2i Size
Definition types.hpp:370
@ WINDOW_AUTOSIZE
the user cannot resize the window, the size is constrainted by the image displayed.
Definition highgui.hpp:144
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
@ CAP_PROP_FOURCC
4-character code of codec. see VideoWriter::fourcc .
Definition videoio.hpp:148
@ CAP_PROP_FRAME_WIDTH
Width of the frames in the video stream.
Definition videoio.hpp:145
@ CAP_PROP_FRAME_HEIGHT
Height of the frames in the video stream.
Definition videoio.hpp:146
@ CAP_PROP_FPS
Frame rate.
Definition videoio.hpp:147
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Definition dnn_superres.hpp:26
"black box" representation of the file storage associated with a file on disk.
Definition core.hpp:102