mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Add static to local function
This commit is contained in:
parent
f893ee5cec
commit
4a9c84c570
@ -232,7 +232,57 @@ static ImageEncoder findEncoder( const String& _ext )
|
|||||||
|
|
||||||
enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 };
|
enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 };
|
||||||
|
|
||||||
void RotateImage(const String& filename, Mat& img);
|
static void RotateImage(const String& filename, Mat& img)
|
||||||
|
{
|
||||||
|
int orientation = IMAGE_ORIENTATION_TL;
|
||||||
|
|
||||||
|
if (filename.size() > 0)
|
||||||
|
{
|
||||||
|
ExifReader reader( filename );
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( orientation )
|
||||||
|
{
|
||||||
|
case IMAGE_ORIENTATION_TL: //0th row == visual top, 0th column == visual left-hand side
|
||||||
|
//do nothing, the image already has proper orientation
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_TR: //0th row == visual top, 0th column == visual right-hand side
|
||||||
|
flip(img, img, 1); //flip horizontally
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_BR: //0th row == visual bottom, 0th column == visual right-hand side
|
||||||
|
flip(img, img, -1);//flip both horizontally and vertically
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_BL: //0th row == visual bottom, 0th column == visual left-hand side
|
||||||
|
flip(img, img, 0); //flip vertically
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_LT: //0th row == visual left-hand side, 0th column == visual top
|
||||||
|
transpose(img, img);
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_RT: //0th row == visual right-hand side, 0th column == visual top
|
||||||
|
transpose(img, img);
|
||||||
|
flip(img, img, 1); //flip horizontally
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_RB: //0th row == visual right-hand side, 0th column == visual bottom
|
||||||
|
transpose(img, img);
|
||||||
|
flip(img, img, -1); //flip both horizontally and vertically
|
||||||
|
break;
|
||||||
|
case IMAGE_ORIENTATION_LB: //0th row == visual left-hand side, 0th column == visual bottom
|
||||||
|
transpose(img, img);
|
||||||
|
flip(img, img, 0); //flip vertically
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//by default the image read has normal (JPEG_ORIENTATION_TL) orientation
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an image into memory and return the information
|
* Read an image into memory and return the information
|
||||||
@ -409,7 +459,7 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
|
|||||||
if (!decoder->readData(mat))
|
if (!decoder->readData(mat))
|
||||||
{
|
{
|
||||||
// optionally rotate the data if EXIF' orientation flag says so
|
// optionally rotate the data if EXIF' orientation flag says so
|
||||||
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 )
|
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
|
||||||
{
|
{
|
||||||
RotateImage(filename, mat);
|
RotateImage(filename, mat);
|
||||||
}
|
}
|
||||||
@ -427,59 +477,6 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
|
|||||||
return !mats.empty();
|
return !mats.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateImage(const String& filename, Mat& img)
|
|
||||||
{
|
|
||||||
int orientation = IMAGE_ORIENTATION_TL;
|
|
||||||
|
|
||||||
if (filename.size() > 0)
|
|
||||||
{
|
|
||||||
ExifReader reader( filename );
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch( orientation )
|
|
||||||
{
|
|
||||||
case IMAGE_ORIENTATION_TL: //0th row == visual top, 0th column == visual left-hand side
|
|
||||||
//do nothing, the image already has proper orientation
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_TR: //0th row == visual top, 0th column == visual right-hand side
|
|
||||||
flip(img, img, 1); //flip horizontally
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_BR: //0th row == visual bottom, 0th column == visual right-hand side
|
|
||||||
flip(img, img, -1);//flip both horizontally and vertically
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_BL: //0th row == visual bottom, 0th column == visual left-hand side
|
|
||||||
flip(img, img, 0); //flip vertically
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_LT: //0th row == visual left-hand side, 0th column == visual top
|
|
||||||
transpose(img, img);
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_RT: //0th row == visual right-hand side, 0th column == visual top
|
|
||||||
transpose(img, img);
|
|
||||||
flip(img, img, 1); //flip horizontally
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_RB: //0th row == visual right-hand side, 0th column == visual bottom
|
|
||||||
transpose(img, img);
|
|
||||||
flip(img, img, -1); //flip both horizontally and vertically
|
|
||||||
break;
|
|
||||||
case IMAGE_ORIENTATION_LB: //0th row == visual left-hand side, 0th column == visual bottom
|
|
||||||
transpose(img, img);
|
|
||||||
flip(img, img, 0); //flip vertically
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//by default the image read has normal (JPEG_ORIENTATION_TL) orientation
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an image
|
* Read an image
|
||||||
*
|
*
|
||||||
@ -497,7 +494,7 @@ Mat imread( const String& filename, int flags )
|
|||||||
imread_( filename, flags, LOAD_MAT, &img );
|
imread_( filename, flags, LOAD_MAT, &img );
|
||||||
|
|
||||||
/// optionally rotate the data if EXIF' orientation flag says so
|
/// optionally rotate the data if EXIF' orientation flag says so
|
||||||
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 )
|
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
|
||||||
{
|
{
|
||||||
RotateImage(filename, img);
|
RotateImage(filename, img);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user