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
bc3c7e80
Commit
bc3c7e80
authored
Jul 21, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9209 from alalek:fix_persistence_format
parents
32683ee6
ec7ce814
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
3 deletions
+84
-3
persistence.hpp
modules/core/include/opencv2/core/persistence.hpp
+5
-0
persistence.cpp
modules/core/src/persistence.cpp
+23
-3
test_io.cpp
modules/core/test/test_io.cpp
+56
-0
No files found.
modules/core/include/opencv2/core/persistence.hpp
View file @
bc3c7e80
...
@@ -462,6 +462,11 @@ public:
...
@@ -462,6 +462,11 @@ public:
*/
*/
static
String
getDefaultObjectName
(
const
String
&
filename
);
static
String
getDefaultObjectName
(
const
String
&
filename
);
/** @brief Returns the current format.
* @returns The current format, see FileStorage::Mode
*/
CV_WRAP
int
getFormat
()
const
;
Ptr
<
CvFileStorage
>
fs
;
//!< the underlying C FileStorage structure
Ptr
<
CvFileStorage
>
fs
;
//!< the underlying C FileStorage structure
String
elname
;
//!< the currently written element
String
elname
;
//!< the currently written element
std
::
vector
<
char
>
structs
;
//!< the stack of written structures
std
::
vector
<
char
>
structs
;
//!< the stack of written structures
...
...
modules/core/src/persistence.cpp
View file @
bc3c7e80
...
@@ -4270,11 +4270,25 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
...
@@ -4270,11 +4270,25 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
if
(
fmt
==
CV_STORAGE_FORMAT_AUTO
&&
filename
)
if
(
fmt
==
CV_STORAGE_FORMAT_AUTO
&&
filename
)
{
{
const
char
*
dot_pos
=
strrchr
(
filename
,
'.'
);
const
char
*
dot_pos
=
NULL
;
const
char
*
dot_pos2
=
NULL
;
// like strrchr() implementation, but save two last positions simultaneously
for
(
const
char
*
pos
=
filename
;
pos
[
0
]
!=
0
;
pos
++
)
{
if
(
pos
[
0
]
==
'.'
)
{
dot_pos2
=
dot_pos
;
dot_pos
=
pos
;
}
}
if
(
cv_strcasecmp
(
dot_pos
,
".gz"
)
&&
dot_pos2
!=
NULL
)
{
dot_pos
=
dot_pos2
;
}
fs
->
fmt
fs
->
fmt
=
cv_strcasecmp
(
dot_pos
,
".xml"
)
=
(
cv_strcasecmp
(
dot_pos
,
".xml"
)
||
cv_strcasecmp
(
dot_pos
,
".xml.gz"
)
)
?
CV_STORAGE_FORMAT_XML
?
CV_STORAGE_FORMAT_XML
:
cv_strcasecmp
(
dot_pos
,
".json"
)
:
(
cv_strcasecmp
(
dot_pos
,
".json"
)
||
cv_strcasecmp
(
dot_pos
,
".json.gz"
)
)
?
CV_STORAGE_FORMAT_JSON
?
CV_STORAGE_FORMAT_JSON
:
CV_STORAGE_FORMAT_YAML
:
CV_STORAGE_FORMAT_YAML
;
;
...
@@ -6920,6 +6934,12 @@ FileNode FileStorage::root(int streamidx) const
...
@@ -6920,6 +6934,12 @@ FileNode FileStorage::root(int streamidx) const
return
isOpened
()
?
FileNode
(
fs
,
cvGetRootFileNode
(
fs
,
streamidx
))
:
FileNode
();
return
isOpened
()
?
FileNode
(
fs
,
cvGetRootFileNode
(
fs
,
streamidx
))
:
FileNode
();
}
}
int
FileStorage
::
getFormat
()
const
{
CV_Assert
(
!
fs
.
empty
());
return
fs
->
fmt
&
FORMAT_MASK
;
}
FileStorage
&
operator
<<
(
FileStorage
&
fs
,
const
String
&
str
)
FileStorage
&
operator
<<
(
FileStorage
&
fs
,
const
String
&
str
)
{
{
CV_TRACE_REGION_VERBOSE
();
CV_TRACE_REGION_VERBOSE
();
...
...
modules/core/test/test_io.cpp
View file @
bc3c7e80
...
@@ -1236,3 +1236,59 @@ TEST(Core_InputOutput, FileStorage_DMatch_vector_vector)
...
@@ -1236,3 +1236,59 @@ TEST(Core_InputOutput, FileStorage_DMatch_vector_vector)
}
}
}
}
}
}
TEST
(
Core_InputOutput
,
FileStorage_format_xml
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.xml"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_XML
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_xml_gz
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.xml.gz"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_XML
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_json
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.json"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_JSON
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_json_gz
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.json.gz"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_JSON
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_yaml
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.yaml"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_YAML
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_yaml_gz
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.yaml.gz"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_YAML
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_yml
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.yml"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_YAML
,
fs
.
getFormat
());
}
TEST
(
Core_InputOutput
,
FileStorage_format_yml_gz
)
{
FileStorage
fs
;
fs
.
open
(
"opencv_storage.yml.gz"
,
FileStorage
::
WRITE
|
FileStorage
::
MEMORY
);
EXPECT_EQ
(
FileStorage
::
FORMAT_YAML
,
fs
.
getFormat
());
}
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