当前位置:网站首页>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,推荐大家收藏一份。
下面是部分截图,文末附免费下载方式。
一、人工智能课程及项目

二、国内外知名精华资源

三、人工智能论文合集

四、人工智能行业报告

学好人工智能,要多看书,多动手,多实践,要想提高自己的水平,一定要学会沉下心来慢慢的系统学习,最终才能有所收获。
点击下方名片,扫码免费下载文中资料。
边栏推荐
- Does it count as staying up late to sleep at 2:00 and get up at 10:00? Unless you can do it every day
- MySQL modifies and deletes tables in batches according to the table prefix
- 腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
- About sizeof() and strlen in array
- Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
- Jilin University 22 spring March "official document writing" assignment assessment-00034
- js工具函数,自己封装一个节流函数
- 现在,耳朵也要进入元宇宙了
- IE寿终正寝,网友们搞起了真·墓碑……
- How to choose a securities company when opening an account with a compass? Which is safer
猜你喜欢

香蕉为什么能做随机数生成器?因为,它是水果界的“辐射之王”

你真的需要自动化测试吗?

How to raise key issues in the big talk club?

Maintenant, les oreilles vont entrer dans le métacosme.

The release function completed 02 "IVX low code sign in system production"

可能是拿反了的原因
![[rust submission] review impl trail and dyn trail in rust](/img/bc/05b3e031659ce19d6f6e3887d70512.jpg)
[rust submission] review impl trail and dyn trail in rust

MySQL modifies and deletes tables in batches according to the table prefix

Wuenda, the new course of machine learning is coming again! Free auditing, Xiaobai friendly

X86 CPU, critical! The latest vulnerability has caused heated discussion. Hackers can remotely steal keys. Intel "all processors" are affected
随机推荐
The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised
教你如何在winpe里安装win11系统
js工具函数,自己封装一个节流函数
Tencent's open source project "Yinglong" has become a top-level project of Apache: the former long-term service wechat payment can hold a million billion level of data stream processing
Jilin University 22 spring March "career design" assignment assessment-00072
OpenSUSE installation pit log
Huawei failed to appeal and was prohibited from selling 5g equipment in Sweden; Apple regained the first place in the world in terms of market value; DeNO completes round a financing of USD 21million
Skywalking implements cross thread trace delivery
程序员真人秀又来了!呼兰当主持挑灯狂补知识,SSS大佬本科竟是药学,清华朱军张敏等加入导师团...
腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
Maybe it's the wrong reason
x86 CPU,危!最新漏洞引发热议,黑客可远程窃取密钥,英特尔“全部处理器”受影响...
陆奇首次出手投资量子计算
MySQL根据表前缀批量修改、删除表
What is an SSL certificate and what are the benefits of having an SSL certificate?
ASP.NET会议室预约小程序源码 预约小程序源码
Sun Wu plays Warcraft? There is a picture and a truth
Datetimeformat is invalid under @requestbody
Musk: Twitter should learn from wechat and make 1billion people "live on it" into a super app