当前位置:网站首页>How many images can opencv open?

How many images can opencv open?

2022-06-25 04:07:00 Program type

Recently someone asked a question , It has a size 800MB The image file , Find that you can't pass OpenCV Of imread Function load , Just read , The program just crashed . I asked about the size of the image , After calculating the number of pixels, we found that the total number of pixels has exceeded OpenCV Declare the maximum number of pixels limit , So I can't read it !

opencv The maximum number of images can be opened ?

The size of the open image is related to the computer memory , The higher the running memory, the larger the file that can be opened .

Everybody knows OpenCV The function to read the image in is imread, The functions are as follows :

Mat cv::imread(
         const String &        filename,
         int flags = IMREAD_COLOR
)

Parameter interpretation

  • filename Represents the file path of the input image
  • flags Indicates how the image is loaded

Support includes bmp、jpg、png、webp、pfm、sr、ras、tiff、hdr Image files in the same format

Load super image limit and breakthrough

One of the most common errors encountered when loading large images is

The computer memory is not enough , But most of the time, the computer memory is enough , But still can't load , The reason is simple , Mainly OpenCV The size of the loaded image itself is limited by , The limit is defined in

modules\imgcodecs\src\loadsave.cpp

In this source file , There are three about images imread When the maximum image width 、 high 、 Pixel number size limit , The code defined is :

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);

Explain the following :

  • Maximum image width supported 2^20
  • Maximum image height supported 2^20
  • Maximum number of pixels supported 2^30

function validateInputImageSize Will first verify the size of the image ,

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;
}

Modify restrictions

Want to load image files that exceed these limits , First make sure you have enough memory , Then manually modify OpenCV The source code file , Change the limit to the value you want , Then recompile OpenCV that will do .

Share some of my artificial intelligence learning materials for free , Including some AI Common framework actual combat video 、 Image recognition 、OpenCV、NLQ、 machine learning 、pytorch、 Computer vision 、 Videos such as deep learning and neural network 、 Courseware source code 、 Famous essence resources at home and abroad 、AI Hot papers 、 Industry reports, etc .

For better systematic learning AI, I recommend that you collect one .

Here are some screenshots , Free download method is attached at the end of the article .

One 、 Artificial intelligence courses and projects

Two 、 Famous essence resources at home and abroad

3、 ... and 、 Collection of papers on artificial intelligence

Four 、 AI Industry Report

Learn Artificial Intelligence well , Read more , Do more , practice , If you want to improve your level , We must learn to settle down and learn slowly and systematically , Only in the end can we gain something .

Click on the business card below , Scan the code and download the information for free .

原网站

版权声明
本文为[Program type]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250051510424.html