Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/imgcodecs/include/opencv2/imgcodecs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,13 @@ The function imreadmulti loads a specified range from a multi-page image from th
*/
CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector<Mat>& mats, int start, int count, int flags = IMREAD_ANYCOLOR);

/** @brief Returns the number of images inside the give file
/** @brief Returns the number of images inside the given file

The function imcount will return the number of pages in a multi-page image, or 1 for single-page images
The function imcount returns the number of pages in a multi-page image (e.g. TIFF), the number of frames in an animation (e.g. AVIF), and 1 otherwise.
If the image cannot be decoded, 0 is returned.
@param filename Name of file to be loaded.
@param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR.
@todo when cv::IMREAD_LOAD_GDAL flag used the return value will be 0 or 1 because OpenCV's GDAL decoder doesn't support multi-page reading yet.
*/
CV_EXPORTS_W size_t imcount(const String& filename, int flags = IMREAD_ANYCOLOR);

Expand Down
1 change: 1 addition & 0 deletions modules/imgcodecs/src/grfmt_avif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ bool AvifDecoder::readHeader() {

m_width = decoder_->image->width;
m_height = decoder_->image->height;
m_frame_count = decoder_->imageCount;
channels_ = (decoder_->image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) ? 1 : 3;
if (decoder_->alphaPresent) ++channels_;
bit_depth_ = decoder_->image->depth;
Expand Down
1 change: 1 addition & 0 deletions modules/imgcodecs/src/grfmt_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ BaseImageDecoder::BaseImageDecoder()
m_buf_supported = false;
m_scale_denom = 1;
m_use_rgb = false;
m_frame_count = 1;
}


Expand Down
2 changes: 2 additions & 0 deletions modules/imgcodecs/src/grfmt_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BaseImageDecoder

int width() const { return m_width; }
int height() const { return m_height; }
size_t getFrameCount() const { return m_frame_count; }
virtual int type() const { return m_type; }

ExifEntry_t getExifTag(const ExifTagName tag) const;
Expand Down Expand Up @@ -93,6 +94,7 @@ class BaseImageDecoder
bool m_buf_supported;
bool m_use_rgb; // flag of decode image as RGB order instead of BGR.
ExifReader m_exif;
size_t m_frame_count;
};


Expand Down
1 change: 1 addition & 0 deletions modules/imgcodecs/src/grfmt_tiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ bool TiffDecoder::readHeader()

m_width = wdth;
m_height = hght;
m_frame_count = TIFFNumberOfDirectories(tif);
if (ncn == 3 && photometric == PHOTOMETRIC_LOGLUV)
{
m_type = CV_32FC3;
Expand Down
20 changes: 1 addition & 19 deletions modules/imgcodecs/src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) {
m_decoder->setSource(filename);
CV_Assert(m_decoder->readHeader());

// count the pages of the image collection
size_t count = 1;
while(m_decoder->nextPage()) count++;

m_size = count;
m_size = m_decoder->getFrameCount();
m_pages.resize(m_size);
// Reinitialize the decoder because we advanced to the last page while counting the pages of the image
#ifdef HAVE_GDAL
if (m_flags != IMREAD_UNCHANGED && (m_flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL) {
m_decoder = GdalDecoder().newDecoder();
}
else {
#endif
m_decoder = findDecoder(m_filename);
#ifdef HAVE_GDAL
}
#endif

m_decoder->setSource(m_filename);
m_decoder->readHeader();
}

size_t ImageCollection::Impl::size() const { return m_size; }
Expand Down
1 change: 1 addition & 0 deletions modules/imgcodecs/test/test_avif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ TEST_P(Imgcodecs_Avif_Animation_WriteReadSuite, encode_decode) {
return;
}
EXPECT_NO_THROW(cv::imwritemulti(output, anim_original, encoding_params_));
EXPECT_EQ(anim_original.size(), imcount(output));

// Read from file.
std::vector<cv::Mat> anim;
Expand Down