c++ opencv 等比例缩放以显示大图像

#include <Windows.h> // 引入 Windows 头文件
#pragma comment(lib, "user32.lib")

 

复制代码
void showMat(cv::Mat image)
{
    cv::namedWindow("image", cv::WINDOW_NORMAL); // 设置窗口属性为可调整大小

    // 获取屏幕尺寸
    int screen_width = GetSystemMetrics(SM_CXSCREEN);
    int screen_height = GetSystemMetrics(SM_CYSCREEN);

    // 计算最大显示尺寸
    int max_size = std::min(screen_width, screen_height) * 0.8; // 取屏幕尺寸的 80%
    double scale = std::min(1.0, std::min(1.0 * max_size / image.cols, 1.0 * max_size / image.rows)); // 计算缩放比例

    cv::Mat display_image;
    cv::resize(image, display_image, cv::Size(), scale, scale); // 缩小图像
    cv::imshow("image", display_image); // 显示图像
    cv::resizeWindow("image", display_image.cols, display_image.rows); // 调整窗口大小为图像大小
    cv::waitKey(0); // 等待按键
}
复制代码

 

posted on   空明流光  阅读(967)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2017-04-03 CS程序中XML编码Encode和解码Decode

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示