mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #19540 from asmorkalov:as/openexr_comression_options
OpenEXR compression options * Adding possibility to select the compression type for the OpenEXR format. There are compression modes other than the default that are more suited for certain data. Mainly grainy/noisy data. * Code review fixes. Co-authored-by: Daniel Rydstrom <daniel.rydstrom@sick.se>
This commit is contained in:
committed by
GitHub
parent
ca7518c13b
commit
c131c12fd7
@@ -6,6 +6,17 @@
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
size_t getFileSize(const string& filename)
|
||||
{
|
||||
std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
ifs.seekg(0, std::ios::end);
|
||||
return ifs.tellg();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(Imgcodecs_EXR, readWrite_32FC1)
|
||||
{
|
||||
const string root = cvtest::TS::ptr()->get_data_path();
|
||||
@@ -23,6 +34,8 @@ TEST(Imgcodecs_EXR, readWrite_32FC1)
|
||||
ASSERT_EQ(CV_32FC1,img.type());
|
||||
|
||||
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
|
||||
// Check generated file size to ensure that it's compressed with proper options
|
||||
ASSERT_EQ(396u, getFileSize(filenameOutput));
|
||||
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
|
||||
ASSERT_EQ(img2.type(), img.type());
|
||||
ASSERT_EQ(img2.size(), img.size());
|
||||
@@ -113,5 +126,29 @@ TEST(Imgcodecs_EXR, readWrite_32FC3_half)
|
||||
EXPECT_EQ(0, remove(filenameOutput.c_str()));
|
||||
}
|
||||
|
||||
TEST(Imgcodecs_EXR, readWrite_32FC1_PIZ)
|
||||
{
|
||||
const string root = cvtest::TS::ptr()->get_data_path();
|
||||
const string filenameInput = root + "readwrite/test32FC1.exr";
|
||||
const string filenameOutput = cv::tempfile(".exr");
|
||||
|
||||
|
||||
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
|
||||
ASSERT_FALSE(img.empty());
|
||||
ASSERT_EQ(CV_32FC1, img.type());
|
||||
|
||||
std::vector<int> params;
|
||||
params.push_back(IMWRITE_EXR_COMPRESSION);
|
||||
params.push_back(IMWRITE_EXR_COMPRESSION_PIZ);
|
||||
ASSERT_TRUE(cv::imwrite(filenameOutput, img, params));
|
||||
// Check generated file size to ensure that it's compressed with proper options
|
||||
ASSERT_EQ(849u, getFileSize(filenameOutput));
|
||||
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
|
||||
ASSERT_EQ(img2.type(), img.type());
|
||||
ASSERT_EQ(img2.size(), img.size());
|
||||
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
|
||||
EXPECT_EQ(0, remove(filenameOutput.c_str()));
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user