mirror of
https://github.com/opencv/opencv.git
synced 2025-06-15 14:10:51 +08:00
Merge pull request #26706 from Kumataro:fix26705
imgcodecs: fix EXR tests
This commit is contained in:
commit
bdb6a968ce
@ -235,6 +235,17 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
( (m_iscolor && !m_ischroma) || color) ? 3 : alphasupported ? 2 : 1 ); // number of channels to read may exceed channels in output img
|
( (m_iscolor && !m_ischroma) || color) ? 3 : alphasupported ? 2 : 1 ); // number of channels to read may exceed channels in output img
|
||||||
size_t xStride = floatsize * channelstoread;
|
size_t xStride = floatsize * channelstoread;
|
||||||
|
|
||||||
|
// See https://github.com/opencv/opencv/issues/26705
|
||||||
|
// If ALGO_HINT_ACCURATE is set, read BGR and swap to RGB.
|
||||||
|
// If ALGO_HINT_APPROX is set, read RGB directly.
|
||||||
|
bool doReadRGB = m_use_rgb;
|
||||||
|
bool doPostColorSwap = false; // After decoding, swap BGR to RGB
|
||||||
|
if(m_use_rgb && (getDefaultAlgorithmHint() == ALGO_HINT_ACCURATE) )
|
||||||
|
{
|
||||||
|
doReadRGB = false;
|
||||||
|
doPostColorSwap = true;
|
||||||
|
}
|
||||||
|
|
||||||
AutoBuffer<char> copy_buffer;
|
AutoBuffer<char> copy_buffer;
|
||||||
|
|
||||||
if( !justcopy )
|
if( !justcopy )
|
||||||
@ -373,7 +384,7 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
|
|
||||||
if( m_iscolor )
|
if( m_iscolor )
|
||||||
{
|
{
|
||||||
if (m_use_rgb)
|
if (doReadRGB)
|
||||||
{
|
{
|
||||||
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
||||||
UpSample( data, channelstoread, step / xstep, m_red->xSampling, m_red->ySampling );
|
UpSample( data, channelstoread, step / xstep, m_red->xSampling, m_red->ySampling );
|
||||||
@ -397,7 +408,7 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
|
|
||||||
if( chromatorgb )
|
if( chromatorgb )
|
||||||
{
|
{
|
||||||
if (m_use_rgb)
|
if (doReadRGB)
|
||||||
ChromaToRGB( (float *)data, m_height, channelstoread, step / xstep );
|
ChromaToRGB( (float *)data, m_height, channelstoread, step / xstep );
|
||||||
else
|
else
|
||||||
ChromaToBGR( (float *)data, m_height, channelstoread, step / xstep );
|
ChromaToBGR( (float *)data, m_height, channelstoread, step / xstep );
|
||||||
@ -424,7 +435,7 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
{
|
{
|
||||||
if( chromatorgb )
|
if( chromatorgb )
|
||||||
{
|
{
|
||||||
if (m_use_rgb)
|
if (doReadRGB)
|
||||||
ChromaToRGB( (float *)buffer, 1, defaultchannels, step );
|
ChromaToRGB( (float *)buffer, 1, defaultchannels, step );
|
||||||
else
|
else
|
||||||
ChromaToBGR( (float *)buffer, 1, defaultchannels, step );
|
ChromaToBGR( (float *)buffer, 1, defaultchannels, step );
|
||||||
@ -452,7 +463,7 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
}
|
}
|
||||||
if( color )
|
if( color )
|
||||||
{
|
{
|
||||||
if (m_use_rgb)
|
if (doReadRGB)
|
||||||
{
|
{
|
||||||
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
if( m_red && (m_red->xSampling != 1 || m_red->ySampling != 1) )
|
||||||
UpSampleY( data, defaultchannels, step / xstep, m_red->ySampling );
|
UpSampleY( data, defaultchannels, step / xstep, m_red->ySampling );
|
||||||
@ -477,6 +488,11 @@ bool ExrDecoder::readData( Mat& img )
|
|||||||
|
|
||||||
close();
|
close();
|
||||||
|
|
||||||
|
if(doPostColorSwap)
|
||||||
|
{
|
||||||
|
cvtColor( img, img, cv::COLOR_BGR2RGB );
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ TEST(Imgcodecs_EXR, readWrite_32FC1)
|
|||||||
|
|
||||||
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
|
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
|
||||||
// Check generated file size to ensure that it's compressed with proper options
|
// Check generated file size to ensure that it's compressed with proper options
|
||||||
ASSERT_EQ(396u, getFileSize(filenameOutput));
|
ASSERT_LE(396u, getFileSize(filenameOutput)); // OpenEXR 2
|
||||||
|
ASSERT_LE( getFileSize(filenameOutput), 440u); // OpenEXR 3.2+
|
||||||
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
|
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
|
||||||
ASSERT_EQ(img2.type(), img.type());
|
ASSERT_EQ(img2.type(), img.type());
|
||||||
ASSERT_EQ(img2.size(), img.size());
|
ASSERT_EQ(img2.size(), img.size());
|
||||||
@ -199,7 +200,11 @@ TEST(Imgcodecs_EXR, read_YC_changeDepth)
|
|||||||
|
|
||||||
cvtColor(img_rgb, img_rgb, COLOR_RGB2BGR);
|
cvtColor(img_rgb, img_rgb, COLOR_RGB2BGR);
|
||||||
|
|
||||||
EXPECT_TRUE(cvtest::norm(img, img_rgb, NORM_INF) == 0);
|
// See https://github.com/opencv/opencv/issues/26705
|
||||||
|
// If ALGO_HINT_ACCURATE is set, norm should be 0.
|
||||||
|
// If ALGO_HINT_APPROX is set, norm should be 1(or 0).
|
||||||
|
EXPECT_LE(cvtest::norm(img, img_rgb, NORM_INF),
|
||||||
|
(cv::getDefaultAlgorithmHint() == ALGO_HINT_ACCURATE)?0:1);
|
||||||
|
|
||||||
// Cannot test writing, EXR encoder doesn't support 8U depth
|
// Cannot test writing, EXR encoder doesn't support 8U depth
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user