|
|
|
@ -361,48 +361,15 @@ static void ExifTransform(int orientation, Mat& img) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ApplyExifOrientation(const String& filename, Mat& img) |
|
|
|
|
static void ApplyExifOrientation(ExifEntry_t orientationTag, Mat& img) |
|
|
|
|
{ |
|
|
|
|
int orientation = IMAGE_ORIENTATION_TL; |
|
|
|
|
|
|
|
|
|
if (filename.size() > 0) |
|
|
|
|
if (orientationTag.tag != INVALID_TAG) |
|
|
|
|
{ |
|
|
|
|
std::ifstream stream( filename.c_str(), std::ios_base::in | std::ios_base::binary ); |
|
|
|
|
ExifReader reader( stream ); |
|
|
|
|
if( reader.parse() ) |
|
|
|
|
{ |
|
|
|
|
ExifEntry_t entry = reader.getTag( ORIENTATION ); |
|
|
|
|
if (entry.tag != INVALID_TAG) |
|
|
|
|
{ |
|
|
|
|
orientation = entry.field_u16; //orientation is unsigned short, so check field_u16
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
stream.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ExifTransform(orientation, img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ApplyExifOrientation(const Mat& buf, Mat& img) |
|
|
|
|
{ |
|
|
|
|
int orientation = IMAGE_ORIENTATION_TL; |
|
|
|
|
|
|
|
|
|
if( buf.isContinuous() ) |
|
|
|
|
{ |
|
|
|
|
ByteStreamBuffer bsb( reinterpret_cast<char*>(buf.data), buf.total() * buf.elemSize() ); |
|
|
|
|
std::istream stream( &bsb ); |
|
|
|
|
ExifReader reader( stream ); |
|
|
|
|
if( reader.parse() ) |
|
|
|
|
{ |
|
|
|
|
ExifEntry_t entry = reader.getTag( ORIENTATION ); |
|
|
|
|
if (entry.tag != INVALID_TAG) |
|
|
|
|
{ |
|
|
|
|
orientation = entry.field_u16; //orientation is unsigned short, so check field_u16
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
orientation = orientationTag.field_u16; //orientation is unsigned short, so check field_u16
|
|
|
|
|
ExifTransform(orientation, img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ExifTransform(orientation, img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -518,6 +485,12 @@ imread_( const String& filename, int flags, Mat& mat ) |
|
|
|
|
resize( mat, mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// optionally rotate the data if EXIF orientation flag says so
|
|
|
|
|
if (!mat.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(decoder->getExifTag(ORIENTATION), mat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -614,7 +587,7 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats) |
|
|
|
|
// optionally rotate the data if EXIF' orientation flag says so
|
|
|
|
|
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(filename, mat); |
|
|
|
|
ApplyExifOrientation(decoder->getExifTag(ORIENTATION), mat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mats.push_back(mat); |
|
|
|
@ -645,12 +618,6 @@ Mat imread( const String& filename, int flags ) |
|
|
|
|
/// load the data
|
|
|
|
|
imread_( filename, flags, img ); |
|
|
|
|
|
|
|
|
|
/// optionally rotate the data if EXIF' orientation flag says so
|
|
|
|
|
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(filename, img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// return a reference to the data
|
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
@ -889,6 +856,12 @@ imdecode_( const Mat& buf, int flags, Mat& mat ) |
|
|
|
|
resize(mat, mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// optionally rotate the data if EXIF' orientation flag says so
|
|
|
|
|
if (!mat.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(decoder->getExifTag(ORIENTATION), mat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -900,12 +873,6 @@ Mat imdecode( InputArray _buf, int flags ) |
|
|
|
|
Mat buf = _buf.getMat(), img; |
|
|
|
|
imdecode_( buf, flags, img ); |
|
|
|
|
|
|
|
|
|
/// optionally rotate the data if EXIF' orientation flag says so
|
|
|
|
|
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(buf, img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -917,12 +884,6 @@ Mat imdecode( InputArray _buf, int flags, Mat* dst ) |
|
|
|
|
dst = dst ? dst : &img; |
|
|
|
|
imdecode_( buf, flags, *dst ); |
|
|
|
|
|
|
|
|
|
/// optionally rotate the data if EXIF' orientation flag says so
|
|
|
|
|
if( !dst->empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) |
|
|
|
|
{ |
|
|
|
|
ApplyExifOrientation(buf, *dst); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return *dst; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|