Skip to content

Commit bb6ea7d

Browse files
MaximSmolskiyNanQin555
authored andcommitted
Merge pull request opencv#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 opencv#26637 ### Pull Request Readiness Checklist Fix opencv#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
1 parent ccc91b7 commit bb6ea7d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

modules/videoio/src/cap_images.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,9 @@ void CvCapture_Images::close()
113113

114114
bool CvCapture_Images::grabFrame()
115115
{
116-
cv::String filename;
117-
if (length == 1)
118-
if (currentframe < length)
119-
filename = filename_pattern;
120-
else
121-
{
122-
return false;
123-
}
124-
else
125-
filename = cv::format(filename_pattern.c_str(), (int)(firstframe + currentframe));
116+
if (length == 1 && currentframe >= length)
117+
return false;
118+
const cv::String filename = cv::format(filename_pattern.c_str(), (int)(firstframe + currentframe));
126119
CV_Assert(!filename.empty());
127120

128121
if (grabbedInOpen)

modules/videoio/test/test_images.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ TEST(videoio_images, extract_pattern)
285285
EXPECT_THROW(cv::icvExtractPattern("1.png", NULL), cv::Exception);
286286
}
287287

288+
TEST(videoio_images, bug_26457)
289+
{
290+
ImageCollection col;
291+
col.generate(1u);
292+
ASSERT_EQ(col.getCount(), 1u);
293+
294+
VideoCapture cap(col.getFirstFilename(), CAP_IMAGES);
295+
ASSERT_TRUE(cap.isOpened());
296+
297+
Mat img;
298+
const bool read_res = cap.read(img);
299+
EXPECT_TRUE(read_res);
300+
EXPECT_MAT_N_DIFF(img, col.getFirstFrame(), 0);
301+
}
302+
288303
// TODO: should writer overwrite files?
289304
// TODO: is clamping good for seeking?
290305
// TODO: missing files? E.g. 3, 4, 6, 7, 8 (should it finish OR jump over OR return empty frame?)

0 commit comments

Comments
 (0)