OpenCV中超分辨率(Super Resolution)模块类cv::dnn_superres::DnnSuperResImpl

  • 操作系统:ubuntu22.04
  • OpenCV版本:OpenCV4.9
  • IDE:Visual Studio Code
  • 编程语言:C++11

算法描述

OpenCV中超分辨率(Super Resolution)模块的一个内部实现类。它属于dnn_superres模块,用于加载和运行基于深度学习的图像超分辨率模型。

这个类是 OpenCV 中用于执行 深度学习超分辨率推理 的主要类。你可以用它来加载预训练的超分辨率模型(如 EDSR、ESPCN、FSRCNN、LapSRN 等),并对图像进行放大。

使用步骤

  1. 创建 DnnSuperRes 对象
cpp 复制代码
#include <opencv2/dnn_superres.hpp>
cv::dnn_superres::DnnSuperResImpl sr;

或者使用智能指针方式:

cpp 复制代码
Ptr<cv::dnn_superres::DnnSuperResImpl> sr = makePtr<cv::dnn_superres::DnnSuperResImpl>();
  1. 加载模型

OpenCV 的超分辨率模块支持以下模型架构:

  • edsr
  • espcn
  • fsrcnn
  • lapsrn

示例代码:

cpp 复制代码
sr.readModel("EDSR_x3.pb"); // 替换为你的模型路径
sr.setModel("edsr", 3);     // 指定模型类型和放大倍数
  1. 超分推理
cpp 复制代码
Mat img = imread("input.jpg");
Mat result;

sr.upsample(img, result);

imwrite("output.jpg", result);

示例代码

cpp 复制代码
#include <opencv2/dnn_superres.hpp>
#include <opencv2/opencv.hpp>

int main()
{
    using namespace cv;
    using namespace cv::dnn_superres;

    // 创建超分辨率对象
    DnnSuperResImpl sr;

    // 加载模型
    sr.readModel( "FSRCNN_x3.pb" );
    sr.setModel( "fsrcnn", 3 );

    // 读取图像
    Mat img = imread( "/media/dingxin/data/study/OpenCV/sources/images/Lenna.png" );
    if ( img.empty() )
    {
        std::cerr << "Failed to load image!" << std::endl;
        return -1;
    }

    // 超分辨率推理
    Mat result;
    sr.upsample( img, result );

    // 保存结果
    imwrite( "output.jpg", result );

    imshow( "Original", img );
    imshow( "Super Resolved", result );
    waitKey( 0 );

    return 0;
}

运行结果

图像确实变得很大,清晰度也没变

代码中模型文件下载地址:https://download.csdn.net/download/jndingxin/91263821

相关推荐
白日梦想家April_Liu几秒前
不蕉绿的青椒手册——审稿篇
人工智能·深度学习·目标检测
小撒的私房菜2 分钟前
Agent = Model + Harness:这个公式,让我重新理解了 AI 工程
人工智能·后端
sheyuDemo3 分钟前
关于小土堆目标检测YOLOv5的一些报错
人工智能·深度学习·yolo·目标检测
乔江seven5 分钟前
【跟李沐学AI】25 物体检测和数据集
人工智能·深度学习·目标检测
Hcoco_me5 分钟前
Ai:Agent/ infra / 智驾 / 推广算法 题库
人工智能·深度学习·算法·自动驾驶·剪枝
何陋轩8 分钟前
Spring AI Function Calling:让AI调用你的Java方法
人工智能·后端·ai编程
Agent手记8 分钟前
空运智能装箱规划自动化、落地方法与合规适配:2026年Agent矩阵驱动的技术演进与实操指引
运维·人工智能·ai·矩阵·自动化
七牛开发者11 分钟前
不写框架、不用 npm,我用 AI Coding 做了一个家庭记忆站
前端·人工智能·npm
FelixZhang02811 分钟前
工业时序工况识别项目复盘:从深度学习探索到 LightGBM/CatBoost 落地
人工智能·深度学习·机器学习·gru·lstm·边缘计算·boosting
智能相对论12 分钟前
应用“深水区”正在被攻克,轮足机器人迎来拐点时刻
大数据·人工智能·机器人