当前位置:网站首页>opencv最大能打开多少图像?
opencv最大能打开多少图像?
2022-06-25 03:44:00 【程序媛珂珂】
最近有人问一个问题,就是它有个大小800MB的图像文件,发现无法通过OpenCV的imread函数加载,只要一读取,程序就直接崩溃了。我问了图像的大小,计算像素数量之后发现总像素数目已经超过了OpenCV声明最大像素数目限制,所以肯定无法读取了!
opencv最大能打开多少图像?
打开图像的大小和电脑的内存有关系,运行内存越高支持打开的文件越大。
大家都知道OpenCV中读取图像的函数是imread,函数功能如下:
Mat cv::imread(
const String & filename,
int flags = IMREAD_COLOR
)参数解释
- filename 表示输入图像的文件路径
- flags 表示加载图像的方式
支持包括bmp、jpg、png、webp、pfm、sr、ras、tiff、hdr等格式图像文件
加载超大图像限制与突破
加载超大图像遇到的最常见的一个错误就是

提示电脑内存不够了,但是很多时候电脑内存是足够,但是还是无法加载,原因很简单,主要是OpenCV本身对加载的图像大小是由限制的,这个限制定义在
modules\imgcodecs\src\loadsave.cpp
这个源码文件中,有三个关于图像imread时候最大图像宽、高、像素数目大小限制,定义的代码为:
static const size_t CV_IO_MAX_IMAGE_WIDTH = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_WIDTH", 1 << 20);
static const size_t CV_IO_MAX_IMAGE_HEIGHT = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_HEIGHT", 1 << 20);
static const size_t CV_IO_MAX_IMAGE_PIXELS = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PIXELS", 1 << 30);解释如下:
- 支持的最大图像宽度 2^20
- 支持的最大图像高度2^20
- 支持的最大像素数目2^30
函数validateInputImageSize会首先校验图像的大小,
static Size validateInputImageSize(const Size& size)
{
CV_Assert(size.width > 0);
CV_Assert(static_cast<size_t>(size.width) <= CV_IO_MAX_IMAGE_WIDTH);
CV_Assert(size.height > 0);
CV_Assert(static_cast<size_t>(size.height) <= CV_IO_MAX_IMAGE_HEIGHT);
uint64 pixels = (uint64)size.width * (uint64)size.height;
CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
return size;
}修改限制
想要加载超过这些限制的图像文件,首先要确保你由足够的内存,然后手动修改OpenCV源码文件,把限制改到你想要的值,然后重新编译OpenCV即可。
免费分享一些我整理的人工智能学习资料给大家,包括一些AI常用框架实战视频、图像识别、OpenCV、NLQ、机器学习、pytorch、计算机视觉、深度学习与神经网络等视频、课件源码、国内外知名精华资源、AI热门论文、行业报告等。
为了更好的系统学习AI,推荐大家收藏一份。
下面是部分截图,文末附免费下载方式。
一、人工智能课程及项目

二、国内外知名精华资源

三、人工智能论文合集

四、人工智能行业报告

学好人工智能,要多看书,多动手,多实践,要想提高自己的水平,一定要学会沉下心来慢慢的系统学习,最终才能有所收获。
点击下方名片,扫码免费下载文中资料。
边栏推荐
- Jilin University 22 spring March "official document writing" assignment assessment-00029
- How far is the memory computing integrated chip from popularization? Listen to what practitioners say | collision school x post friction intelligence
- 墨天轮访谈 | IvorySQL王志斌—IvorySQL,一个基于PostgreSQL的兼容Oracle的开源数据库
- 腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
- Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
- Is it safe to open an account online? Online and other answers
- 居家办公之后才明白的时间管理 | 社区征文
- Now, the ear is going into the metauniverse
- MySQL modifies and deletes tables in batches according to the table prefix
- Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
猜你喜欢

服乔布斯不服库克,苹果传奇设计团队解散内幕曝光

About PLSQL error initialization failure

现在,耳朵也要进入元宇宙了

如何使用IDE自动签名调试鸿蒙应用

Disassembly of Weima prospectus: the electric competition has ended and the intelligent qualifying has just begun

Background page production 01 production of IVX low code sign in system

ICML 2022 | ByteDance AI Lab proposes a multimodal model: x-vlm, learning multi granularity alignment of vision and language

程序猿职业发展9项必备软技能

x86 CPU,危!最新漏洞引发热议,黑客可远程窃取密钥,英特尔“全部处理器”受影响...

How to raise key issues in the big talk club?
随机推荐
Comprehensive assignment of thesis writing instruction of Dongcai
Demonstration of combination of dream CAD cloud map and GIS
How to play well in the PMP Exam?
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
Apple's legendary design team disbanded after jobs refused to obey cook
OpenSUSE installation pit log
一文搞懂php中的(DI)依赖注入
Comprehensive operation of financial risk management X of Dongcai
服乔布斯不服库克,苹果传奇设计团队解散内幕曝光
腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
Nacos practice record
Amazon's other side in China
js工具函数,自己封装一个节流函数
现在,耳朵也要进入元宇宙了
香蕉为什么能做随机数生成器?因为,它是水果界的“辐射之王”
Lu Qi invests in quantum computing for the first time
中国天眼发现地外文明可疑信号,马斯克称星舰7月开始轨道试飞,网信办:APP不得强制要求用户同意处理个人信息,今日更多大新闻在此...
Redis related-03
Teach you how to install win11 system in winpe
Tensorflow, danger! Google itself is the one who abandoned it