Skip to content

Commit 4c1fb00

Browse files
Saafkealalek
authored andcommitted
Merge pull request #2231 from Saafke:dnn_superres_final_phase
* Add learning-based super-resolution module Adds the module plus loading classes for SR data Complete with docs, tutorials and tests. * Fix typo * Small commit to restart buildbot * Change refs from arXiv to official * Remove video string * dnn_superres: update perf test code * dnn_superres: test fixup
1 parent dda33bf commit 4c1fb00

21 files changed

+697
-15
lines changed

modules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_<r
2222

2323
- **datasets**: Datasets Reader -- Code for reading existing computer vision databases and samples of using the readers to train, test and run using that dataset's data.
2424

25-
- **dnn_objdetect**: Object Detection using CNNs -- Implements compact CNN Model for object detection. Trained using Caffe but uses opencv_dnn modeule.
25+
- **dnn_objdetect**: Object Detection using CNNs -- Implements compact CNN Model for object detection. Trained using Caffe but uses opencv_dnn module.
2626

2727
- **dnn_superres**: Superresolution using CNNs -- Contains four trained convolutional neural networks to upscale images.
2828

modules/datasets/include/opencv2/datasets/dataset.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,53 @@ Implements loading dataset:
435435
./opencv/build/bin/example_datasets_slam_tumindoor -p=/home/user/path_to_unpacked_folders/
436436
~~~
437437
438+
@defgroup datasets_sr Super Resolution
439+
440+
### The Berkeley Segmentation Dataset and Benchmark
441+
442+
Implements loading dataset:
443+
444+
"The Berkeley Segmentation Dataset and Benchmark": <https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/>
445+
446+
Usage:
447+
-# From link above download `BSDS300-images.tgz`.
448+
-# Unpack.
449+
-# To load data run:
450+
~~~
451+
./opencv/build/bin/example_datasets_sr_bsds -p=/home/user/path_to_unpacked_folder/
452+
~~~
453+
454+
### DIV2K dataset: DIVerse 2K
455+
456+
Implements loading dataset:
457+
458+
"DIV2K dataset: DIVerse 2K": <https://data.vision.ee.ethz.ch/cvl/DIV2K/>
459+
460+
Usage:
461+
-# From link above download 'Train data (HR images)' or any other of the dataset files.
462+
-# Unpack.
463+
-# To load data run:
464+
~~~
465+
./opencv/build/bin/example_datasets_sr_div2k -p=/home/user/path_to_unpacked_folder/folder_containing_the_images/
466+
~~~
467+
468+
### The General-100 Dataset
469+
470+
Implements loading dataset:
471+
472+
"General-100 dataset contains 100 bmp-format images (with no compression).
473+
We used this dataset in our FSRCNN ECCV 2016 paper. The size of these 100 images ranges from 710 x 704 (large) to 131 x 112 (small).
474+
They are all of good quality with clear edges but fewer smooth regions (e.g., sky and ocean), thus are very suitable for the super-resolution training.":
475+
<http://mmlab.ie.cuhk.edu.hk/projects/FSRCNN.html>
476+
477+
Usage:
478+
-# From link above download `General-100.zip`.
479+
-# Unpack.
480+
-# To load data run:
481+
~~~
482+
./opencv/build/bin/example_datasets_sr_general100 -p=/home/user/path_to_unpacked_folder/
483+
~~~
484+
438485
@defgroup datasets_tr Text Recognition
439486
440487
### The Chars74K Dataset
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_DATASETS_SR_BSDS_HPP
6+
#define OPENCV_DATASETS_SR_BSDS_HPP
7+
8+
#include <string>
9+
#include <vector>
10+
11+
#include "opencv2/datasets/dataset.hpp"
12+
13+
#include <opencv2/core.hpp>
14+
15+
namespace cv
16+
{
17+
namespace datasets
18+
{
19+
20+
//! @addtogroup datasets_sr
21+
//! @{
22+
23+
struct SR_bsdsObj : public Object
24+
{
25+
std::string imageName;
26+
};
27+
28+
class CV_EXPORTS SR_bsds : public Dataset
29+
{
30+
public:
31+
virtual void load(const std::string &path) CV_OVERRIDE = 0;
32+
33+
static Ptr<SR_bsds> create();
34+
};
35+
36+
//! @}
37+
38+
}
39+
}
40+
41+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_DATASETS_SR_DIV2K_HPP
6+
#define OPENCV_DATASETS_SR_DIV2K_HPP
7+
8+
#include <string>
9+
#include <vector>
10+
11+
#include "opencv2/datasets/dataset.hpp"
12+
13+
#include <opencv2/core.hpp>
14+
15+
namespace cv
16+
{
17+
namespace datasets
18+
{
19+
20+
//! @addtogroup datasets_sr
21+
//! @{
22+
23+
struct SR_div2kObj : public Object
24+
{
25+
std::string imageName;
26+
};
27+
28+
class CV_EXPORTS SR_div2k : public Dataset
29+
{
30+
public:
31+
virtual void load(const std::string &path) CV_OVERRIDE = 0;
32+
33+
static Ptr<SR_div2k> create();
34+
};
35+
36+
//! @}
37+
38+
}
39+
}
40+
41+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_DATASETS_SR_GENERAL100_HPP
6+
#define OPENCV_DATASETS_SR_GENERAL100_HPP
7+
8+
#include <string>
9+
#include <vector>
10+
11+
#include "opencv2/datasets/dataset.hpp"
12+
13+
#include <opencv2/core.hpp>
14+
15+
namespace cv
16+
{
17+
namespace datasets
18+
{
19+
20+
//! @addtogroup datasets_sr
21+
//! @{
22+
23+
struct SR_general100Obj : public Object
24+
{
25+
std::string imageName;
26+
};
27+
28+
class CV_EXPORTS SR_general100 : public Dataset
29+
{
30+
public:
31+
virtual void load(const std::string &path) CV_OVERRIDE = 0;
32+
33+
static Ptr<SR_general100> create();
34+
};
35+
36+
//! @}
37+
38+
}
39+
}
40+
41+
#endif

modules/datasets/samples/sr_bsds.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "opencv2/datasets/sr_bsds.hpp"
6+
7+
#include <opencv2/core.hpp>
8+
9+
#include <cstdio>
10+
11+
#include <string>
12+
#include <vector>
13+
14+
using namespace std;
15+
using namespace cv;
16+
using namespace cv::datasets;
17+
18+
int main(int argc, char *argv[])
19+
{
20+
const char *keys =
21+
"{ help h usage ? | | show this message }"
22+
"{ path p |true| path to dataset (images, iids_train.txt, iids_test.txt) }";
23+
CommandLineParser parser(argc, argv, keys);
24+
string path(parser.get<string>("path"));
25+
if (parser.has("help") || path=="true")
26+
{
27+
parser.printMessage();
28+
return -1;
29+
}
30+
31+
Ptr<SR_bsds> dataset = SR_bsds::create();
32+
dataset->load(path);
33+
34+
// ***************
35+
// Dataset train & test contain names of appropriate images.
36+
// For example, let's output full path & name for first train and test images.
37+
// And dataset sizes.
38+
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
39+
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
40+
41+
SR_bsdsObj *example1 = static_cast<SR_bsdsObj *>(dataset->getTrain()[0].get());
42+
string fullPath(path + "images/train/" + example1->imageName + ".jpg");
43+
printf("first train image: %s\n", fullPath.c_str());
44+
45+
SR_bsdsObj *example2 = static_cast<SR_bsdsObj *>(dataset->getTest()[0].get());
46+
fullPath = path + "images/test/" + example2->imageName + ".jpg";
47+
printf("first test image: %s\n", fullPath.c_str());
48+
49+
return 0;
50+
}

modules/datasets/samples/sr_div2k.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "opencv2/datasets/sr_div2k.hpp"
6+
7+
#include <opencv2/core.hpp>
8+
9+
#include <cstdio>
10+
11+
#include <string>
12+
#include <vector>
13+
14+
using namespace std;
15+
using namespace cv;
16+
using namespace cv::datasets;
17+
18+
int main(int argc, char *argv[])
19+
{
20+
const char *keys =
21+
"{ help h usage ? | | show this message }"
22+
"{ path p |true| path to dataset (Div2k dataset folder containing the images) }";
23+
CommandLineParser parser(argc, argv, keys);
24+
string path(parser.get<string>("path"));
25+
if (parser.has("help") || path=="true")
26+
{
27+
parser.printMessage();
28+
return -1;
29+
}
30+
31+
Ptr<SR_div2k> dataset = SR_div2k::create();
32+
dataset->load(path);
33+
34+
// ***************
35+
// Dataset contains all images.
36+
// For example, let's output dataset size; first image name; and second image full path.
37+
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
38+
39+
SR_div2kObj *example = static_cast<SR_div2kObj *>(dataset->getTrain()[0].get());
40+
printf("first image name: %s\n", example->imageName.c_str());
41+
42+
SR_div2kObj *example2 = static_cast<SR_div2kObj *>(dataset->getTrain()[1].get());
43+
string fullPath = path + "/" + example2->imageName.c_str();
44+
printf("second image full path: %s\n", fullPath.c_str());
45+
46+
return 0;
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "opencv2/datasets/sr_general100.hpp"
6+
7+
#include <opencv2/core.hpp>
8+
9+
#include <cstdio>
10+
11+
#include <string>
12+
#include <vector>
13+
14+
using namespace std;
15+
using namespace cv;
16+
using namespace cv::datasets;
17+
18+
int main(int argc, char *argv[])
19+
{
20+
const char *keys =
21+
"{ help h usage ? | | show this message }"
22+
"{ path p |true| path to dataset (General-100 dataset folder) }";
23+
CommandLineParser parser(argc, argv, keys);
24+
string path(parser.get<string>("path"));
25+
if (parser.has("help") || path=="true")
26+
{
27+
parser.printMessage();
28+
return -1;
29+
}
30+
31+
Ptr<SR_general100> dataset = SR_general100::create();
32+
dataset->load(path);
33+
34+
// ***************
35+
// Dataset contains all images.
36+
// For example, let's output dataset size; first image name; and second image full path.
37+
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
38+
39+
SR_general100Obj *example = static_cast<SR_general100Obj *>(dataset->getTrain()[0].get());
40+
printf("first image name: %s\n", example->imageName.c_str());
41+
42+
SR_general100Obj *example2 = static_cast<SR_general100Obj *>(dataset->getTrain()[1].get());
43+
string fullPath = path + "/" + example2->imageName.c_str();
44+
printf("second image full path: %s\n", fullPath.c_str());
45+
46+
return 0;
47+
}

0 commit comments

Comments
 (0)