Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4a9c84c5
Commit
4a9c84c5
authored
Nov 10, 2016
by
Arkadiusz Raj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add static to local function
parent
f893ee5c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
56 deletions
+53
-56
loadsave.cpp
modules/imgcodecs/src/loadsave.cpp
+53
-56
No files found.
modules/imgcodecs/src/loadsave.cpp
View file @
4a9c84c5
...
...
@@ -232,7 +232,57 @@ static ImageEncoder findEncoder( const String& _ext )
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
...
...
@@ -409,7 +459,7 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
if
(
!
decoder
->
readData
(
mat
))
{
// 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
);
}
...
...
@@ -427,59 +477,6 @@ imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
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
*
...
...
@@ -497,7 +494,7 @@ Mat imread( const String& filename, int flags )
imread_
(
filename
,
flags
,
LOAD_MAT
,
&
img
);
/// 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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment