mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #26859 from Kumataro:fix26858
imgcodecs:gif: support IMREAD_UNCHANGED and IMREAD_GRAYSCALE #26859 Close #26858 ### 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:
@@ -164,6 +164,8 @@ TEST_P(Imgcodecs_ExtSize, write_imageseq)
|
||||
continue;
|
||||
if (cn != 3 && ext == ".ppm")
|
||||
continue;
|
||||
if (cn == 1 && ext == ".gif")
|
||||
continue;
|
||||
string filename = cv::tempfile(format("%d%s", cn, ext.c_str()).c_str());
|
||||
|
||||
Mat img_gt(size, CV_MAKETYPE(CV_8U, cn), Scalar::all(0));
|
||||
@@ -179,8 +181,14 @@ TEST_P(Imgcodecs_ExtSize, write_imageseq)
|
||||
ASSERT_TRUE(imwrite(filename, img_gt, parameters));
|
||||
Mat img = imread(filename, IMREAD_UNCHANGED);
|
||||
ASSERT_FALSE(img.empty());
|
||||
EXPECT_EQ(img.size(), img.size());
|
||||
EXPECT_EQ(img.type(), img.type());
|
||||
EXPECT_EQ(img_gt.size(), img.size());
|
||||
EXPECT_EQ(img_gt.channels(), img.channels());
|
||||
if (ext == ".pfm") {
|
||||
EXPECT_EQ(img_gt.depth(), CV_8U);
|
||||
EXPECT_EQ(img.depth(), CV_32F);
|
||||
} else {
|
||||
EXPECT_EQ(img_gt.depth(), img.depth());
|
||||
}
|
||||
EXPECT_EQ(cn, img.channels());
|
||||
|
||||
|
||||
@@ -200,6 +208,14 @@ TEST_P(Imgcodecs_ExtSize, write_imageseq)
|
||||
EXPECT_LT(n, 1.);
|
||||
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), img, img_gt);
|
||||
}
|
||||
else if (ext == ".gif")
|
||||
{
|
||||
// GIF encoder will reduce the number of colors to 256.
|
||||
// It is hard to compare image comparison by pixel unit.
|
||||
double n = cvtest::norm(img, img_gt, NORM_L1);
|
||||
double expected = 0.03 * img.size().area();
|
||||
EXPECT_LT(n, expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
double n = cvtest::norm(img, img_gt, NORM_L2);
|
||||
@@ -238,6 +254,9 @@ const string all_exts[] =
|
||||
#ifdef HAVE_IMGCODEC_PFM
|
||||
".pfm",
|
||||
#endif
|
||||
#ifdef HAVE_IMGCODEC_GIF
|
||||
".gif",
|
||||
#endif
|
||||
};
|
||||
|
||||
vector<Size> all_sizes()
|
||||
|
||||
Reference in New Issue
Block a user