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
6ff58f02
Commit
6ff58f02
authored
Jul 30, 2014
by
edgarriba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code tutorial
parent
94968c81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
CsvReader.cpp
..._code/calib3d/real_time_pose_estimation/src/CsvReader.cpp
+81
-0
No files found.
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp
0 → 100644
View file @
6ff58f02
#include <boost/lexical_cast.hpp>
#include "CsvReader.h"
/** The default constructor of the CSV reader Class */
CsvReader
::
CsvReader
(
const
std
::
string
&
path
,
const
char
&
separator
){
_file
.
open
(
path
.
c_str
(),
ifstream
::
in
);
_separator
=
separator
;
}
/* Read a plane text file with .ply format */
void
CsvReader
::
readPLY
(
std
::
vector
<
cv
::
Point3f
>
&
list_vertex
,
std
::
vector
<
std
::
vector
<
int
>
>
&
list_triangles
)
{
std
::
string
line
,
tmp_str
,
n
;
int
num_vertex
,
num_triangles
;
int
count
=
0
;
bool
end_header
=
false
;
bool
end_vertex
=
false
;
// Read the whole *.ply file
while
(
getline
(
_file
,
line
))
{
stringstream
liness
(
line
);
// read header
if
(
!
end_header
)
{
getline
(
liness
,
tmp_str
,
_separator
);
if
(
tmp_str
==
"element"
)
{
getline
(
liness
,
tmp_str
,
_separator
);
getline
(
liness
,
n
);
if
(
tmp_str
==
"vertex"
)
num_vertex
=
boost
::
lexical_cast
<
int
>
(
n
);
if
(
tmp_str
==
"face"
)
num_triangles
=
boost
::
lexical_cast
<
int
>
(
n
);
}
if
(
tmp_str
==
"end_header"
)
end_header
=
true
;
}
// read file content
else
if
(
end_header
)
{
// read vertex and add into 'list_vertex'
if
(
!
end_vertex
&&
count
<
num_vertex
)
{
string
x
,
y
,
z
;
getline
(
liness
,
x
,
_separator
);
getline
(
liness
,
y
,
_separator
);
getline
(
liness
,
z
);
cv
::
Point3f
tmp_p
;
tmp_p
.
x
=
boost
::
lexical_cast
<
float
>
(
x
);
tmp_p
.
y
=
boost
::
lexical_cast
<
float
>
(
y
);
tmp_p
.
z
=
boost
::
lexical_cast
<
float
>
(
z
);
list_vertex
.
push_back
(
tmp_p
);
count
++
;
if
(
count
==
num_vertex
)
{
count
=
0
;
end_vertex
=
!
end_vertex
;
}
}
// read faces and add into 'list_triangles'
else
if
(
end_vertex
&&
count
<
num_triangles
)
{
std
::
string
num_pts_per_face
,
id0
,
id1
,
id2
;
getline
(
liness
,
num_pts_per_face
,
_separator
);
getline
(
liness
,
id0
,
_separator
);
getline
(
liness
,
id1
,
_separator
);
getline
(
liness
,
id2
);
std
::
vector
<
int
>
tmp_triangle
(
3
);
tmp_triangle
[
0
]
=
boost
::
lexical_cast
<
int
>
(
id0
);
tmp_triangle
[
1
]
=
boost
::
lexical_cast
<
int
>
(
id1
);
tmp_triangle
[
2
]
=
boost
::
lexical_cast
<
int
>
(
id2
);
list_triangles
.
push_back
(
tmp_triangle
);
count
++
;
}
}
}
}
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