1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge branch '4.x' into '5.x'

This commit is contained in:
Maksim Shabunin
2024-06-11 19:38:59 +03:00
573 changed files with 72922 additions and 7355 deletions
@@ -87,8 +87,8 @@ enum ImwriteFlags {
IMWRITE_JPEG_PROGRESSIVE = 2, //!< Enable JPEG features, 0 or 1, default is False.
IMWRITE_JPEG_OPTIMIZE = 3, //!< Enable JPEG features, 0 or 1, default is False.
IMWRITE_JPEG_RST_INTERVAL = 4, //!< JPEG restart interval, 0 - 65535, default is 0 - no restart.
IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is -1 - don't use.
IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is -1 - don't use.
IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is -1 - don't use. If JPEG_LIB_VERSION < 70, Not supported.
IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is -1 - don't use. If JPEG_LIB_VERSION < 70, Not supported.
IMWRITE_JPEG_SAMPLING_FACTOR = 7, //!< For JPEG, set sampling factor. See cv::ImwriteJPEGSamplingFactorParams.
IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). Default value is 1 (best speed setting).
IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE.
+5
View File
@@ -5,6 +5,9 @@
namespace opencv_test
{
#ifdef HAVE_JPEG
using namespace perf;
PERF_TEST(JPEG, Decode)
@@ -35,4 +38,6 @@ PERF_TEST(JPEG, Encode)
SANITY_CHECK_NOTHING();
}
#endif // HAVE_JPEG
} // namespace
+5
View File
@@ -6,6 +6,9 @@
namespace opencv_test
{
#if defined(HAVE_PNG) || defined(HAVE_SPNG)
using namespace perf;
typedef perf::TestBaseWithParam<std::string> PNG;
@@ -38,4 +41,6 @@ PERF_TEST(PNG, encode)
SANITY_CHECK_NOTHING();
}
#endif // HAVE_PNG
} // namespace
+1 -1
View File
@@ -729,7 +729,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& params )
Mat exrMat;
if( type == HALF )
{
convertFp16(img, exrMat);
img.convertTo(exrMat, CV_16F);
buffer = (char *)const_cast<uchar *>( exrMat.ptr() );
bufferstep = exrMat.step;
size = 2;
+12 -4
View File
@@ -93,10 +93,18 @@ bool HdrDecoder::readData(Mat& _img)
RGBE_ReadPixels_RLE(file, const_cast<float*>(img.ptr<float>()), img.cols, img.rows);
fclose(file); file = NULL;
if(_img.depth() == img.depth()) {
img.convertTo(_img, _img.type());
} else {
img.convertTo(_img, _img.type(), 255);
// NOTE: 'img' has type CV32FC3
switch (_img.depth())
{
case CV_8U: img.convertTo(img, _img.depth(), 255); break;
case CV_32F: break;
default: CV_Error(Error::StsError, "Wrong expected image depth, allowed: CV_8U and CV_32F");
}
switch (_img.channels())
{
case 1: cvtColor(img, _img, COLOR_BGR2GRAY); break;
case 3: img.copyTo(_img); break;
default: CV_Error(Error::StsError, "Wrong expected image channels, allowed: 1 and 3");
}
return true;
}
+61 -32
View File
@@ -619,11 +619,6 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
std::vector<uchar> out_buf(1 << 12);
#ifndef JCS_EXTENSIONS
AutoBuffer<uchar> _buffer;
uchar* buffer;
#endif
struct jpeg_compress_struct cinfo;
JpegErrorMgr jerr;
JpegDestination dest;
@@ -658,14 +653,40 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
int _channels = img.channels();
int channels = _channels > 1 ? 3 : 1;
bool doDirectWrite = false;
switch( _channels )
{
case 1:
cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE;
doDirectWrite = true; // GRAY -> GRAY
break;
case 3:
#ifdef JCS_EXTENSIONS
cinfo.input_components = _channels;
cinfo.in_color_space = _channels == 3 ? JCS_EXT_BGR
: _channels == 4 ? JCS_EXT_BGRX : JCS_GRAYSCALE;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_EXT_BGR;
doDirectWrite = true; // BGR -> BGR
#else
cinfo.input_components = channels;
cinfo.in_color_space = channels > 1 ? JCS_RGB : JCS_GRAYSCALE;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
doDirectWrite = false; // BGR -> RGB
#endif
break;
case 4:
#ifdef JCS_EXTENSIONS
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_BGRX;
doDirectWrite = true; // BGRX -> BGRX
#else
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
doDirectWrite = false; // BGRA -> RGB
#endif
break;
default:
CV_Error(cv::Error::StsError, cv::format("Unsupported number of _channels: %06d", _channels) );
break;
}
int quality = 95;
int progressive = 0;
@@ -762,9 +783,9 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
cinfo.comp_info[1].h_samp_factor = 1;
}
#if JPEG_LIB_VERSION >= 70
if (luma_quality >= 0 && chroma_quality >= 0)
{
#if JPEG_LIB_VERSION >= 70
cinfo.q_scale_factor[0] = jpeg_quality_scaling(luma_quality);
cinfo.q_scale_factor[1] = jpeg_quality_scaling(chroma_quality);
if ( luma_quality != chroma_quality )
@@ -776,35 +797,43 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
cinfo.comp_info[1].h_samp_factor = 1;
}
jpeg_default_qtables( &cinfo, TRUE );
}
#else
// See https://github.com/opencv/opencv/issues/25646
CV_LOG_ONCE_WARNING(NULL, cv::format("IMWRITE_JPEG_LUMA/CHROMA_QUALITY are not supported bacause JPEG_LIB_VERSION < 70."));
#endif // #if JPEG_LIB_VERSION >= 70
}
jpeg_start_compress( &cinfo, TRUE );
#ifndef JCS_EXTENSIONS
if( channels > 1 )
_buffer.allocate(width*channels);
buffer = _buffer.data();
#endif
for( int y = 0; y < height; y++ )
if( doDirectWrite )
{
uchar *data = img.data + img.step*y, *ptr = data;
#ifndef JCS_EXTENSIONS
if( _channels == 3 )
for( int y = 0; y < height; y++ )
{
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, Size(width,1) );
ptr = buffer;
uchar *data = const_cast<uchar*>(img.ptr<uchar>(y));
jpeg_write_scanlines( &cinfo, &data, 1 );
}
else if( _channels == 4 )
{
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, Size(width,1), 2 );
ptr = buffer;
}
#endif
}
else
{
CV_Check(_channels, (_channels == 3) || (_channels == 4), "Unsupported number of channels(indirect write)");
jpeg_write_scanlines( &cinfo, &ptr, 1 );
AutoBuffer<uchar> _buffer;
_buffer.allocate(width*channels);
uchar *buffer = _buffer.data();
for( int y = 0; y < height; y++ )
{
uchar *data = const_cast<uchar*>(img.ptr<uchar>(y));
if( _channels == 3 )
{
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, Size(width,1) );
}
else // if( _channels == 4 )
{
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, Size(width,1), 2 );
}
jpeg_write_scanlines( &cinfo, &buffer, 1 );
}
}
jpeg_finish_compress( &cinfo );
+31 -66
View File
@@ -81,6 +81,22 @@ static Size validateInputImageSize(const Size& size)
}
static inline int calcType(int type, int flags)
{
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if( (flags & IMREAD_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & IMREAD_COLOR) != 0 ||
((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
return type;
}
namespace {
class ByteStreamBuffer: public std::streambuf
@@ -328,7 +344,7 @@ static ImageEncoder findEncoder( const String& _ext )
}
static void ExifTransform(int orientation, Mat& img)
static void ExifTransform(int orientation, OutputArray img)
{
switch( orientation )
{
@@ -365,7 +381,7 @@ static void ExifTransform(int orientation, Mat& img)
}
}
static void ApplyExifOrientation(ExifEntry_t orientationTag, Mat& img)
static void ApplyExifOrientation(ExifEntry_t orientationTag, OutputArray img)
{
int orientation = IMAGE_ORIENTATION_TL;
@@ -385,7 +401,7 @@ static void ApplyExifOrientation(ExifEntry_t orientationTag, Mat& img)
*
*/
static bool
imread_( const String& filename, int flags, Mat& mat )
imread_( const String& filename, int flags, OutputArray mat )
{
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
@@ -444,18 +460,7 @@ imread_( const String& filename, int flags, Mat& mat )
Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
// grab the decoded type
int type = decoder->type();
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if( (flags & IMREAD_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & IMREAD_COLOR) != 0 ||
((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
const int type = calcType(decoder->type(), flags);
if (mat.empty())
{
@@ -469,11 +474,16 @@ imread_( const String& filename, int flags, Mat& mat )
}
// read the image data
Mat real_mat = mat.getMat();
const void * original_ptr = real_mat.data;
bool success = false;
try
{
if (decoder->readData(mat))
if (decoder->readData(real_mat))
{
CV_CheckTrue(original_ptr == real_mat.data, "Internal imread issue");
success = true;
}
}
catch (const cv::Exception& e)
{
@@ -567,18 +577,7 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats, int star
while (current < count)
{
// grab the decoded type
int type = decoder->type();
if ((flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED)
{
if ((flags & IMREAD_ANYDEPTH) == 0)
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if ((flags & IMREAD_COLOR) != 0 ||
((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1))
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
const int type = calcType(decoder->type(), flags);
// established the required input image size
Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
@@ -645,10 +644,8 @@ void imread( const String& filename, OutputArray dst, int flags )
{
CV_TRACE_FUNCTION();
Mat img = dst.getMat();
/// load the data
imread_(filename, flags, img);
imread_(filename, flags, dst);
}
/**
@@ -866,18 +863,7 @@ imdecode_( const Mat& buf, int flags, Mat& mat )
// established the required input image size
Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
int type = decoder->type();
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if( (flags & IMREAD_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & IMREAD_COLOR) != 0 ||
((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
const int type = calcType(decoder->type(), flags);
mat.create( size.height, size.width, type );
@@ -1028,18 +1014,7 @@ imdecodemulti_(const Mat& buf, int flags, std::vector<Mat>& mats, int start, int
while (current < count)
{
// grab the decoded type
int type = decoder->type();
if ((flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED)
{
if ((flags & IMREAD_ANYDEPTH) == 0)
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if ((flags & IMREAD_COLOR) != 0 ||
((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1))
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
const int type = calcType(decoder->type(), flags);
// established the required input image size
Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
@@ -1279,17 +1254,7 @@ bool ImageCollection::Impl::readHeader() {
// readHeader must be called before calling this method
Mat ImageCollection::Impl::readData() {
int type = m_decoder->type();
if ((m_flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && m_flags != IMREAD_UNCHANGED) {
if ((m_flags & IMREAD_ANYDEPTH) == 0)
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if ((m_flags & IMREAD_COLOR) != 0 ||
((m_flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1))
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
const int type = calcType(m_decoder->type(), m_flags);
// established the required input image size
Size size = validateInputImageSize(Size(m_width, m_height));
+6
View File
@@ -87,11 +87,17 @@ const string all_images[] =
"readwrite/uint16-mono2.dcm",
"readwrite/uint8-rgb.dcm",
#endif
#if defined(HAVE_PNG) || defined(HAVE_SPNG)
"readwrite/color_palette_alpha.png",
#endif
#ifdef HAVE_TIFF
"readwrite/multipage.tif",
#endif
"readwrite/ordinary.bmp",
"readwrite/rle8.bmp",
#ifdef HAVE_JPEG
"readwrite/test_1_c1.jpg",
#endif
#ifdef HAVE_IMGCODEC_HDR
"readwrite/rle.hdr"
#endif
+62
View File
@@ -7,6 +7,10 @@ namespace opencv_test { namespace {
#ifdef HAVE_JPEG
extern "C" {
#include "jpeglib.h"
}
/**
* Test for check whether reading exif orientation tag was processed successfully or not
* The test info is the set of 8 images named testExifRotate_{1 to 8}.jpg
@@ -308,6 +312,64 @@ TEST(Imgcodecs_Jpeg, encode_subsamplingfactor_usersetting_invalid)
}
}
//==================================================================================================
// See https://github.com/opencv/opencv/issues/25646
typedef testing::TestWithParam<std::tuple<int, int>> Imgcodecs_Jpeg_encode_withLumaChromaQuality;
TEST_P(Imgcodecs_Jpeg_encode_withLumaChromaQuality, basic)
{
const int luma = get<0>(GetParam());
const int chroma = get<1>(GetParam());
cvtest::TS& ts = *cvtest::TS::ptr();
string fname = string(ts.get_data_path()) + "../cv/shared/lena.png";
cv::Mat src = imread(fname, cv::IMREAD_COLOR);
ASSERT_FALSE(src.empty());
std::vector<uint8_t> jpegNormal;
ASSERT_NO_THROW(cv::imencode(".jpg", src, jpegNormal));
std::vector<int> param;
param.push_back(IMWRITE_JPEG_LUMA_QUALITY);
param.push_back(luma);
param.push_back(IMWRITE_JPEG_CHROMA_QUALITY);
param.push_back(chroma);
std::vector<uint8_t> jpegCustom;
ASSERT_NO_THROW(cv::imencode(".jpg", src, jpegCustom, param));
#if JPEG_LIB_VERSION >= 70
// For jpeg7+, we can support IMWRITE_JPEG_LUMA_QUALITY and IMWRITE_JPEG_CHROMA_QUALITY.
if( (luma == 95 /* Default Luma Quality */ ) && ( chroma == 95 /* Default Chroma Quality */))
{
EXPECT_EQ(jpegNormal, jpegCustom);
}
else
{
EXPECT_NE(jpegNormal, jpegCustom);
}
#else
// For jpeg6-, we cannot support IMWRITE_JPEG_LUMA/CHROMA_QUALITY because jpeg_default_qtables() is missing.
// - IMWRITE_JPEG_LUMA_QUALITY updates internal parameter of IMWRITE_JPEG_QUALITY.
// - IMWRITE_JPEG_CHROMA_QUALITY updates nothing.
if( luma == 95 /* Default Jpeg Quality */ )
{
EXPECT_EQ(jpegNormal, jpegCustom);
}
else
{
EXPECT_NE(jpegNormal, jpegCustom);
}
#endif
}
INSTANTIATE_TEST_CASE_P( /* nothing */,
Imgcodecs_Jpeg_encode_withLumaChromaQuality,
testing::Combine(
testing::Values(70, 95, 100), // IMWRITE_JPEG_LUMA_QUALITY
testing::Values(70, 95, 100) )); // IMWRITE_JPEG_CHROMA_QUALITY
#endif // HAVE_JPEG
}} // namespace
-13
View File
@@ -7,19 +7,6 @@ namespace opencv_test { namespace {
#if defined(HAVE_PNG) || defined(HAVE_SPNG)
TEST(Imgcodecs_Png, imread_passing_mat)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string imgName = root + "../cv/shared/lena.png";
Mat ref = imread(imgName);
Mat img(ref.size(), ref.type());
void* ptr = img.data;
imread(imgName, img);
EXPECT_EQ(cv::norm(ref, img, NORM_INF), 0);
EXPECT_EQ(img.data, ptr);
}
TEST(Imgcodecs_Png, write_big)
{
const string root = cvtest::TS::ptr()->get_data_path();
@@ -282,6 +282,35 @@ TEST(Imgcodecs_Image, regression_9376)
EXPECT_EQ(32, m.rows);
}
TEST(Imgcodecs_Image, imread_overload)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string imgName = findDataFile("../highgui/readwrite/ordinary.bmp");
Mat ref = imread(imgName);
ASSERT_FALSE(ref.empty());
{
Mat img(ref.size(), ref.type(), Scalar::all(0)); // existing image
void * ptr = img.data;
imread(imgName, img);
ASSERT_FALSE(img.empty());
EXPECT_EQ(cv::norm(ref, img, NORM_INF), 0);
EXPECT_EQ(img.data, ptr); // no reallocation
}
{
Mat img; // empty image
imread(imgName, img);
ASSERT_FALSE(img.empty());
EXPECT_EQ(cv::norm(ref, img, NORM_INF), 0);
}
{
UMat img; // empty UMat
imread(imgName, img);
ASSERT_FALSE(img.empty());
EXPECT_EQ(cv::norm(ref, img, NORM_INF), 0);
}
}
//==================================================================================================
TEST(Imgcodecs_Image, write_umat)
@@ -303,6 +332,7 @@ TEST(Imgcodecs_Image, write_umat)
EXPECT_EQ(0, remove(dst_name.c_str()));
}
#ifdef HAVE_TIFF
TEST(Imgcodecs_Image, multipage_collection_size)
{
const string root = cvtest::TS::ptr()->get_data_path();
@@ -479,6 +509,7 @@ TEST(ImgCodecs, multipage_collection_two_iterator_operatorpp)
EXPECT_TRUE(cv::norm(img1, img[i], NORM_INF) == 0);
}
}
#endif
TEST(Imgcodecs_Params, imwrite_regression_22752)
+59 -19
View File
@@ -685,15 +685,22 @@ TEST(Imgcodecs_Tiff, readWrite_unsigned)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/gray_8u.tif";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_8UC1, img.type());
Mat matS8;
img.convertTo(matS8, CV_8SC1);
ASSERT_TRUE(cv::imwrite(filenameOutput, matS8));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(filenameOutput, matS8));
ASSERT_TRUE(ret_imwrite);
Mat img2;
ASSERT_NO_THROW(img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED));
ASSERT_FALSE(img2.empty());
ASSERT_EQ(img2.type(), matS8.type());
ASSERT_EQ(img2.size(), matS8.size());
EXPECT_LE(cvtest::norm(matS8, img2, NORM_INF | NORM_RELATIVE), 1e-3);
@@ -705,12 +712,19 @@ TEST(Imgcodecs_Tiff, readWrite_32FC1)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test32FC1.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_32FC1,img.type());
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(filenameOutput, img));
ASSERT_TRUE(ret_imwrite);
Mat img2;
ASSERT_NO_THROW(img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED));
ASSERT_FALSE(img2.empty());
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
@@ -722,12 +736,19 @@ TEST(Imgcodecs_Tiff, readWrite_64FC1)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test64FC1.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_64FC1, img.type());
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(filenameOutput, img));
ASSERT_TRUE(ret_imwrite);
Mat img2;
ASSERT_NO_THROW(img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED));
ASSERT_FALSE(img2.empty());
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
@@ -739,12 +760,19 @@ TEST(Imgcodecs_Tiff, readWrite_32FC3_SGILOG)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test32FC3_sgilog.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_32FC3, img.type());
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(filenameOutput, img));
ASSERT_TRUE(ret_imwrite);
Mat img2;
ASSERT_NO_THROW(img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED));
ASSERT_FALSE(img2.empty());
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 0.01);
@@ -756,7 +784,9 @@ TEST(Imgcodecs_Tiff, readWrite_32FC3_RAW)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test32FC3_raw.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_32FC3, img.type());
@@ -764,8 +794,13 @@ TEST(Imgcodecs_Tiff, readWrite_32FC3_RAW)
params.push_back(IMWRITE_TIFF_COMPRESSION);
params.push_back(IMWRITE_TIFF_COMPRESSION_NONE);
ASSERT_TRUE(cv::imwrite(filenameOutput, img, params));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(filenameOutput, img, params));
ASSERT_TRUE(ret_imwrite);
Mat img2;
ASSERT_NO_THROW(img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED));
ASSERT_FALSE(img2.empty());
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
@@ -777,7 +812,8 @@ TEST(Imgcodecs_Tiff, read_palette_color_image)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test_palette_color_image.tif";
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_8UC3, img.type());
}
@@ -787,7 +823,8 @@ TEST(Imgcodecs_Tiff, read_4_bit_palette_color_image)
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/4-bit_palette_color.tif";
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(filenameInput, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_8UC3, img.type());
}
@@ -825,9 +862,12 @@ TEST(Imgcodecs_Tiff, readWrite_predictor)
params.push_back(IMWRITE_TIFF_PREDICTOR);
params.push_back(IMWRITE_TIFF_PREDICTOR_HORIZONTAL);
EXPECT_NO_THROW(cv::imwrite(out, mat, params));
bool ret_imwrite = false;
ASSERT_NO_THROW(ret_imwrite = cv::imwrite(out, mat, params));
ASSERT_TRUE(ret_imwrite);
const Mat img = cv::imread(out, IMREAD_UNCHANGED);
Mat img;
ASSERT_NO_THROW(img = cv::imread(out, IMREAD_UNCHANGED));
ASSERT_FALSE(img.empty());
ASSERT_EQ(0, cv::norm(mat, img, cv::NORM_INF));