使用OpenCV实现图像超分辨率(C++)

#include <opencv2/dnn_superres.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace std;
using namespace cv;
using namespace dnn;
using namespace dnn_superres;

int main(int argc, char* argv[]) {
    
    
	DnnSuperResImpl sr;  // 创建模块对象
	string img_path = "F:/SuperResolution/test_image_720p.jpg";  // 图像路径
	Mat img = cv::imread(img_path);  // 读取图像
	string trained_model_path = "F:/SuperResolution/TF-ESPCN/export/ESPCN_x2.pb";  // 模型路径
	sr.readModel(trained_model_path);  // 读取模型
	sr.setModel("espcn", 2);  // 放大图像
	Mat img_new;
	sr.upsample(img, img_new);  // 上采样
	cv::imwrite("F:/SuperResolution/result_image_2k.jpg", img_new);  // 保存2k图像

	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_48158964/article/details/131614131