mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #26211 from Kumataro:fix26207
imgcodecs: implement imencodemulti() #26211 Close #26207 ### Pull Request Readiness Checklist 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 - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -520,8 +520,78 @@ TEST(ImgCodecs, multipage_collection_two_iterator_operatorpp)
|
||||
EXPECT_TRUE(cv::norm(img1, img[i], NORM_INF) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
// See https://github.com/opencv/opencv/issues/26207
|
||||
TEST(Imgcodecs, imencodemulti_regression_26207)
|
||||
{
|
||||
vector<Mat> imgs;
|
||||
const cv::Mat img(100, 100, CV_8UC1, cv::Scalar::all(0));
|
||||
imgs.push_back(img);
|
||||
std::vector<uchar> buf;
|
||||
bool ret = false;
|
||||
|
||||
// Encode single image
|
||||
EXPECT_NO_THROW(ret = imencode(".tiff", img, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_NO_THROW(ret = imencode(".tiff", imgs, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_NO_THROW(ret = imencodemulti(".tiff", imgs, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
// Encode multiple images
|
||||
imgs.push_back(img.clone());
|
||||
EXPECT_NO_THROW(ret = imencode(".tiff", imgs, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_NO_THROW(ret = imencodemulti(".tiff", imgs, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
// Count stored images from buffer.
|
||||
// imcount() doesn't support buffer, so encoded buffer outputs to file temporary.
|
||||
const size_t len = buf.size();
|
||||
const string filename = cv::tempfile(".tiff");
|
||||
FILE *f = fopen(filename.c_str(), "wb");
|
||||
EXPECT_NE(f, nullptr);
|
||||
EXPECT_EQ(len, fwrite(&buf[0], 1, len, f));
|
||||
fclose(f);
|
||||
|
||||
EXPECT_EQ(2, (int)imcount(filename));
|
||||
EXPECT_EQ(0, remove(filename.c_str()));
|
||||
}
|
||||
#endif
|
||||
|
||||
// See https://github.com/opencv/opencv/pull/26211
|
||||
// ( related with https://github.com/opencv/opencv/issues/26207 )
|
||||
TEST(Imgcodecs, imencode_regression_26207_extra)
|
||||
{
|
||||
// CV_32F is not supported depth for BMP Encoder.
|
||||
// Encoded buffer contains CV_8U image which is fallbacked.
|
||||
const cv::Mat src(100, 100, CV_32FC1, cv::Scalar::all(0));
|
||||
std::vector<uchar> buf;
|
||||
bool ret = false;
|
||||
EXPECT_NO_THROW(ret = imencode(".bmp", src, buf));
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
cv::Mat dst;
|
||||
EXPECT_NO_THROW(dst = imdecode(buf, IMREAD_GRAYSCALE));
|
||||
EXPECT_FALSE(dst.empty());
|
||||
EXPECT_EQ(CV_8UC1, dst.type());
|
||||
}
|
||||
TEST(Imgcodecs, imwrite_regression_26207_extra)
|
||||
{
|
||||
// CV_32F is not supported depth for BMP Encoder.
|
||||
// Encoded buffer contains CV_8U image which is fallbacked.
|
||||
const cv::Mat src(100, 100, CV_32FC1, cv::Scalar::all(0));
|
||||
const string filename = cv::tempfile(".bmp");
|
||||
bool ret = false;
|
||||
EXPECT_NO_THROW(ret = imwrite(filename, src));
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
cv::Mat dst;
|
||||
EXPECT_NO_THROW(dst = imread(filename, IMREAD_GRAYSCALE));
|
||||
EXPECT_FALSE(dst.empty());
|
||||
EXPECT_EQ(CV_8UC1, dst.type());
|
||||
EXPECT_EQ(0, remove(filename.c_str()));
|
||||
}
|
||||
|
||||
TEST(Imgcodecs_Params, imwrite_regression_22752)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user