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
c979de1e
Commit
c979de1e
authored
Apr 02, 2013
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite Mat formatting without std streams
parent
7193a73c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
102 additions
and
72 deletions
+102
-72
operations.hpp
modules/core/include/opencv2/core/operations.hpp
+44
-60
traits.hpp
modules/core/include/opencv2/core/traits.hpp
+45
-0
out.cpp
modules/core/src/out.cpp
+0
-0
test_io.cpp
modules/core/test/test_io.cpp
+1
-0
window_gtk.cpp
modules/highgui/src/window_gtk.cpp
+2
-2
cout_mat.cpp
samples/cpp/cout_mat.cpp
+6
-6
mat_the_basic_image_container.cpp
...e_basic_image_container/mat_the_basic_image_container.cpp
+4
-4
No files found.
modules/core/include/opencv2/core/operations.hpp
View file @
c979de1e
...
...
@@ -400,96 +400,80 @@ template<typename _Tp> static inline _Tp randu()
//////////////////////////////////////////////////////////////////////////////
class
CV_EXPORTS
Formatte
r
class
CV_EXPORTS
Formatte
d
{
public
:
virtual
~
Formatter
()
{}
virtual
void
write
(
std
::
ostream
&
out
,
const
Mat
&
m
,
const
int
*
params
=
0
,
int
nparams
=
0
)
const
=
0
;
virtual
void
write
(
std
::
ostream
&
out
,
const
void
*
data
,
int
nelems
,
int
type
,
const
int
*
params
=
0
,
int
nparams
=
0
)
const
=
0
;
static
const
Formatter
*
get
(
const
char
*
fmt
=
""
);
static
const
Formatter
*
setDefault
(
const
Formatter
*
fmt
);
virtual
const
char
*
next
()
=
0
;
virtual
void
reset
()
=
0
;
virtual
~
Formatted
();
};
struct
CV_EXPORTS
Formatted
class
CV_EXPORTS
Formatter
{
Formatted
(
const
Mat
&
m
,
const
Formatter
*
fmt
,
const
std
::
vector
<
int
>&
params
);
Formatted
(
const
Mat
&
m
,
const
Formatter
*
fmt
,
const
int
*
params
=
0
);
Mat
mtx
;
const
Formatter
*
fmt
;
std
::
vector
<
int
>
params
;
};
public
:
enum
{
FMT_MATLAB
=
0
,
FMT_CSV
=
1
,
FMT_PYTHON
=
2
,
FMT_NUMPY
=
3
,
FMT_C
=
4
,
FMT_DEFAULT
=
FMT_MATLAB
};
static
inline
Formatted
format
(
const
Mat
&
mtx
,
const
char
*
fmt
,
const
std
::
vector
<
int
>&
params
=
std
::
vector
<
int
>
())
{
return
Formatted
(
mtx
,
Formatter
::
get
(
fmt
),
params
);
}
virtual
~
Formatter
();
template
<
typename
_Tp
>
static
inline
Formatted
format
(
const
std
::
vector
<
Point_
<
_Tp
>
>&
vec
,
const
char
*
fmt
,
const
std
::
vector
<
int
>&
params
=
std
::
vector
<
int
>
())
{
return
Formatted
(
Mat
(
vec
),
Formatter
::
get
(
fmt
),
params
)
;
}
virtual
Ptr
<
Formatted
>
format
(
const
Mat
&
mtx
)
const
=
0
;
virtual
void
set32fPrecision
(
int
p
=
8
)
=
0
;
virtual
void
set64fPrecision
(
int
p
=
16
)
=
0
;
virtual
void
setMultiline
(
bool
ml
=
true
)
=
0
;
template
<
typename
_Tp
>
static
inline
Formatted
format
(
const
std
::
vector
<
Point3_
<
_Tp
>
>&
vec
,
const
char
*
fmt
,
const
std
::
vector
<
int
>&
params
=
std
::
vector
<
int
>
())
static
Ptr
<
Formatter
>
get
(
int
fmt
=
FMT_DEFAULT
);
};
static
inline
Ptr
<
Formatted
>
format
(
InputArray
mtx
,
int
fmt
)
{
return
Formatte
d
(
Mat
(
vec
),
Formatter
::
get
(
fmt
),
params
);
return
Formatte
r
::
get
(
fmt
)
->
format
(
mtx
.
getMat
()
);
}
/** \brief prints Mat to the output stream in Matlab notation
* use like
@verbatim
Mat my_mat = Mat::eye(3,3,CV_32F);
std::cout << my_mat;
@endverbatim
*/
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Mat
&
mtx
)
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
Ptr
<
Formatted
>
fmtd
)
{
Formatter
::
get
()
->
write
(
out
,
mtx
);
fmtd
->
reset
();
for
(
const
char
*
str
=
fmtd
->
next
();
str
;
str
=
fmtd
->
next
())
out
<<
str
;
return
out
;
}
/** \brief prints Mat to the output stream allows in the specified notation (see format)
* use like
@verbatim
Mat my_mat = Mat::eye(3,3,CV_32F);
std::cout << my_mat;
@endverbatim
*/
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Formatted
&
fmtd
)
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Mat
&
mtx
)
{
fmtd
.
fmt
->
write
(
out
,
fmtd
.
mtx
);
return
out
;
return
out
<<
Formatter
::
get
()
->
format
(
mtx
);
}
template
<
typename
_Tp
>
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
std
::
vector
<
Point_
<
_Tp
>
>&
vec
)
template
<
typename
_Tp
>
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
std
::
vector
<
Point_
<
_Tp
>
>&
vec
)
{
Formatter
::
get
()
->
write
(
out
,
Mat
(
vec
));
return
out
;
return
out
<<
Formatter
::
get
()
->
format
(
Mat
(
vec
));
}
template
<
typename
_Tp
>
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
std
::
vector
<
Point3_
<
_Tp
>
>&
vec
)
template
<
typename
_Tp
>
static
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
std
::
vector
<
Point3_
<
_Tp
>
>&
vec
)
{
Formatter
::
get
()
->
write
(
out
,
Mat
(
vec
));
return
out
;
return
out
<<
Formatter
::
get
()
->
format
(
Mat
(
vec
));
}
/** Writes a Matx to an output stream.
*/
template
<
typename
_Tp
,
int
m
,
int
n
>
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Matx
<
_Tp
,
m
,
n
>&
matx
)
template
<
typename
_Tp
,
int
m
,
int
n
>
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Matx
<
_Tp
,
m
,
n
>&
matx
)
{
out
<<
cv
::
Mat
(
matx
);
return
out
;
return
out
<<
Formatter
::
get
()
->
format
(
matx
);
}
/** Writes a point to an output stream in Matlab notation
...
...
modules/core/include/opencv2/core/traits.hpp
View file @
c979de1e
...
...
@@ -227,6 +227,51 @@ public:
};
};
template
<
int
depth
>
class
TypeDepth
{};
template
<>
class
TypeDepth
<
CV_8U
>
{
enum
{
depth
=
CV_8U
};
typedef
uchar
value_type
;
};
template
<>
class
TypeDepth
<
CV_8S
>
{
enum
{
depth
=
CV_8S
};
typedef
schar
value_type
;
};
template
<>
class
TypeDepth
<
CV_16U
>
{
enum
{
depth
=
CV_16U
};
typedef
ushort
value_type
;
};
template
<>
class
TypeDepth
<
CV_16S
>
{
enum
{
depth
=
CV_16S
};
typedef
short
value_type
;
};
template
<>
class
TypeDepth
<
CV_32S
>
{
enum
{
depth
=
CV_32S
};
typedef
int
value_type
;
};
template
<>
class
TypeDepth
<
CV_32F
>
{
enum
{
depth
=
CV_32F
};
typedef
float
value_type
;
};
template
<>
class
TypeDepth
<
CV_64F
>
{
enum
{
depth
=
CV_64F
};
typedef
double
value_type
;
};
}
// cv
#endif // __OPENCV_CORE_TRAITS_HPP__
modules/core/src/out.cpp
View file @
c979de1e
This diff is collapsed.
Click to expand it.
modules/core/test/test_io.cpp
View file @
c979de1e
...
...
@@ -378,6 +378,7 @@ protected:
TEST
(
Core_InputOutput
,
write_read_consistency
)
{
Core_IOTest
test
;
test
.
safe_run
();
}
extern
void
testFormatter
();
class
CV_MiscIOTest
:
public
cvtest
::
BaseTest
{
...
...
modules/highgui/src/window_gtk.cpp
View file @
c979de1e
...
...
@@ -1501,8 +1501,8 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
{
// TODO move this logic to CvImageWidget
CvWindow
*
window
=
(
CvWindow
*
)
user_data
;
CvPoint2D32f
pt32f
=
{
-
1.
,
-
1.
}
;
CvPoint
pt
=
{
-
1
,
-
1
}
;
CvPoint2D32f
pt32f
(
-
1.
,
-
1.
)
;
CvPoint
pt
(
-
1
,
-
1
)
;
int
cv_event
=
-
1
,
state
=
0
;
CvImageWidget
*
image_widget
=
CV_IMAGE_WIDGET
(
widget
);
...
...
samples/cpp/cout_mat.cpp
View file @
c979de1e
...
...
@@ -30,16 +30,16 @@ int main(int,char**)
help
();
Mat
I
=
Mat
::
eye
(
4
,
4
,
CV_64F
);
I
.
at
<
double
>
(
1
,
1
)
=
CV_PI
;
cout
<<
"I =
"
<<
I
<<
";"
<<
endl
;
cout
<<
"I =
\n
"
<<
I
<<
";"
<<
endl
<<
endl
;
Mat
r
=
Mat
(
10
,
3
,
CV_8UC3
);
randu
(
r
,
Scalar
::
all
(
0
),
Scalar
::
all
(
255
));
cout
<<
"r (default) = "
<<
r
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (python) =
"
<<
format
(
r
,
"python"
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (numpy) =
"
<<
format
(
r
,
"numpy"
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (csv) =
"
<<
format
(
r
,
"csv"
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (c) =
"
<<
format
(
r
,
"C"
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (default) =
\n
"
<<
r
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (python) =
\n
"
<<
format
(
r
,
Formatter
::
FMT_PYTHON
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (numpy) =
\n
"
<<
format
(
r
,
Formatter
::
FMT_NUMPY
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (csv) =
\n
"
<<
format
(
r
,
Formatter
::
FMT_CSV
)
<<
";"
<<
endl
<<
endl
;
cout
<<
"r (c) =
\n
"
<<
format
(
r
,
Formatter
::
FMT_C
)
<<
";"
<<
endl
<<
endl
;
Point2f
p
(
5
,
1
);
cout
<<
"p = "
<<
p
<<
";"
<<
endl
;
...
...
samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
View file @
c979de1e
...
...
@@ -59,10 +59,10 @@ int main(int,char**)
// Demonstrate the output formating options
cout
<<
"R (default) = "
<<
endl
<<
R
<<
endl
<<
endl
;
cout
<<
"R (python) = "
<<
endl
<<
format
(
R
,
"python"
)
<<
endl
<<
endl
;
cout
<<
"R (numpy) = "
<<
endl
<<
format
(
R
,
"numpy"
)
<<
endl
<<
endl
;
cout
<<
"R (csv) = "
<<
endl
<<
format
(
R
,
"csv"
)
<<
endl
<<
endl
;
cout
<<
"R (c) = "
<<
endl
<<
format
(
R
,
"C"
)
<<
endl
<<
endl
;
cout
<<
"R (python) = "
<<
endl
<<
format
(
R
,
Formatter
::
FMT_PYTHON
)
<<
endl
<<
endl
;
cout
<<
"R (numpy) = "
<<
endl
<<
format
(
R
,
Formatter
::
FMT_NUMPY
)
<<
endl
<<
endl
;
cout
<<
"R (csv) = "
<<
endl
<<
format
(
R
,
Formatter
::
FMT_CSV
)
<<
endl
<<
endl
;
cout
<<
"R (c) = "
<<
endl
<<
format
(
R
,
Formatter
::
FMT_C
)
<<
endl
<<
endl
;
Point2f
P
(
5
,
1
);
cout
<<
"Point (2D) = "
<<
P
<<
endl
<<
endl
;
...
...
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