opencv图像金字塔

下采样:

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

int main() {
	// 读取图像
	cv::Mat src = cv::imread("C:/Users/10623/Pictures/adf4d0d56444414cbeb809f0933b9214.png");
	if (src.empty()) {
		std::cout << "无法加载图像" << std::endl;
		return -1;
	}

	// 创建一个与源图像同样大小的 Mat 对象,用于存储结果
	cv::Mat dst1,dst2,dst3;

	// 使用 pyrDown 进行向下采样
	cv::pyrDown(src, dst1);
	cv::pyrDown(dst1, dst2);
	cv::pyrDown(dst2, dst3);
	// 显示原始图像和下采样后的图像
	cv::imshow("Original Image", src);
	cv::imshow("Downsampled Image", dst1);
	cv::imshow("2",dst2);
	cv::imshow("3",dst3);
	cv::waitKey(0);

	return 0;
}
cpp 复制代码
#include <opencv2/opencv.hpp>
#include <iostream>

int main() {
    // 读取图像
    cv::Mat src = cv::imread("path_to_your_image.jpg");
    if (src.empty()) {
        std::cout << "无法加载图像" << std::endl;
        return -1;
    }

    // 创建一个向量来存储多尺度金字塔的图像
    std::vector<cv::Mat> images;

    // 使用 buildPyramid 创建多尺度金字塔
    int scale = 1;
    while (src.size().width > 10 && src.size().height > 10) {
        cv::Mat image;
        cv::pyrDown(src, image);  // 使用 pyrDown 进行向下采样
        images.push_back(image);
        src = image;
        scale *= 2;
    }

    // 显示原始图像和多尺度金字塔的图像
    for (int i = images.size() - 1; i >= 0; i--) {
        std::cout << "Scale: " << scale << std::endl;
        cv::imshow("Image", images[i]);
        cv::waitKey(0);
        scale /= 2;
    }

    return 0;
}

上采样:

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

int main() {
	// 读取图像
	cv::Mat src = cv::imread("C:/Users/10623/Pictures/adf4d0d56444414cbeb809f0933b9214.png");
	if (src.empty()) {
		std::cout << "无法加载图像" << std::endl;
		return -1;
	}

	// 创建金字塔参数
	int max_level = 5;  // 最大金字塔层数
	cv::Mat dst,dst1, dst2, dst3,dst4,dst5;
	// 使用 pyrDown 进行向下采样
	cv::pyrDown(src, dst1);
	cv::pyrDown(dst1, dst2);
	cv::pyrDown(dst2, dst3);
	// 构建金字塔
	cv::pyrUp(dst3, dst, cv::Size(dst3.cols * 2, dst3.rows * 2));  // 向上采样到下一层
	cv::pyrUp(dst, dst4, cv::Size(dst.cols * 2, dst.rows * 2));
	cv::pyrUp(dst4, dst5, cv::Size(dst4.cols * 2, dst4.rows * 2));
	cv::imshow("Pyramid Level 1",dst);
	cv::imshow("Pyramid Level 2", dst4);
	cv::imshow("Pyramid Level 3", dst5);
	cv::waitKey(0);
	return 0;
}
相关推荐
Raink老师1 天前
【AI面试临阵磨枪-48】GraphRAG、多模态 RAG、自适应 RAG 原理
人工智能·ai 面试题
波动几何1 天前
模式驱动的学术选题方法论——四种AI模式处理能力的系统建构与论证
人工智能
飞哥数智坊1 天前
我为我的龙虾斩分身:OpenClaw 多智能体实操
人工智能·agent
七牛开发者1 天前
HTML is the new Markdown:来自 Claude Code 团队的实践
前端·人工智能·语言模型·html
飞哥数智坊1 天前
在二线城市做AI社群,我的五一节后到底有多疯狂?
人工智能
视***间1 天前
智启边缘,魔盒藏锋——视程空间Pandora系列魔盒,解锁边缘计算普惠新范式
人工智能·区块链·边缘计算·ai算力·视程空间
蛐蛐蛐1 天前
昇腾910B4上安装新版本CANN的正确流程
人工智能·python·昇腾
沪漂阿龙1 天前
AI大模型面试题:线性回归是什么?最小二乘法、平方误差、正规方程、Ridge、Lasso 一文讲透
人工智能·机器学习·线性回归·最小二乘法
Lyon198505281 天前
《文字定律》让AI体验,汉字逻辑与字母逻辑的差异——ChatGPT
人工智能·ai·chatgpt·ai写作
2601_957780841 天前
Claude 4.6 对阵 GPT-5.4:2026 开发者大模型 API 选型深度解析
人工智能·python·gpt·ai·claude