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

相关推荐
归秋1421 分钟前
多轨音频智能混音软件怎么选:从 demo 到更完整作品的 AI 后期工具思路
人工智能·音视频
DP DPharness5 分钟前
装完看不到模型?dsh-commandcode-provider 排错速查
人工智能·dpharness
天国梦6 分钟前
哪个英语教学软件功能比较全面?我按五个维度拆了一遍
人工智能·机器学习
tomlone20 分钟前
AI 实践:OpenClaw + 本地 Ollama + Qwen3.5
人工智能·自然语言处理·ai写作
盘古开天166620 分钟前
windows鱼塘可交互鱼群动态桌面资源
人工智能·chatgpt·开源
零基础1231 小时前
Agentic Identity:智能体身份识别的核心技术、应用场景与实践指南
人工智能
指针向南1 小时前
canvas最大尺寸是多少:三个浏览器能画、能导出的上限
图像处理·人工智能·计算机视觉
零基础1231 小时前
LLM Agent 驱动的物模型构建:从设备手册到边缘接入的自动化实践
运维·人工智能·经验分享·python·自动化
这张生成的图像能检测吗1 小时前
(论文速读)LINN:液体神经网络与脉冲神经元融合的可解释旋转机械故障诊断
人工智能·深度学习·神经网络·故障诊断