Merge pull request #26637 from MaximSmolskiy:fix-VideoCapture-fails-to-read-single-image-with-digits-in-name

Fix VideoCapture fails to read single image with digits in name #26637

### Pull Request Readiness Checklist

Fix #26457 

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Maxim Smolskiy 2024-12-19 08:17:05 +03:00 committed by GitHub
parent e747ed11cb
commit 9f64f021de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View File

@ -113,16 +113,9 @@ void CvCapture_Images::close()
bool CvCapture_Images::grabFrame()
{
cv::String filename;
if (length == 1)
if (currentframe < length)
filename = filename_pattern;
else
{
return false;
}
else
filename = cv::format(filename_pattern.c_str(), (int)(firstframe + currentframe));
if (length == 1 && currentframe >= length)
return false;
const cv::String filename = cv::format(filename_pattern.c_str(), (int)(firstframe + currentframe));
CV_Assert(!filename.empty());
if (grabbedInOpen)

View File

@ -285,6 +285,21 @@ TEST(videoio_images, extract_pattern)
EXPECT_THROW(cv::icvExtractPattern("1.png", NULL), cv::Exception);
}
TEST(videoio_images, bug_26457)
{
ImageCollection col;
col.generate(1u);
ASSERT_EQ(col.getCount(), 1u);
VideoCapture cap(col.getFirstFilename(), CAP_IMAGES);
ASSERT_TRUE(cap.isOpened());
Mat img;
const bool read_res = cap.read(img);
EXPECT_TRUE(read_res);
EXPECT_MAT_N_DIFF(img, col.getFirstFrame(), 0);
}
// TODO: should writer overwrite files?
// TODO: is clamping good for seeking?
// TODO: missing files? E.g. 3, 4, 6, 7, 8 (should it finish OR jump over OR return empty frame?)