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
43301096
Commit
43301096
authored
Aug 05, 2014
by
edgarriba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tutorial
parent
7b0be9cf
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
49 deletions
+61
-49
CMakeLists.txt
...ial_code/calib3d/real_time_pose_estimation/CMakeLists.txt
+0
-5
CsvReader.cpp
..._code/calib3d/real_time_pose_estimation/src/CsvReader.cpp
+9
-8
CsvReader.h
...al_code/calib3d/real_time_pose_estimation/src/CsvReader.h
+0
-1
CsvWriter.cpp
..._code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp
+10
-10
Utils.cpp
...rial_code/calib3d/real_time_pose_estimation/src/Utils.cpp
+32
-12
Utils.h
...torial_code/calib3d/real_time_pose_estimation/src/Utils.h
+4
-4
main_detection.cpp
.../calib3d/real_time_pose_estimation/src/main_detection.cpp
+4
-5
main_registration.cpp
...lib3d/real_time_pose_estimation/src/main_registration.cpp
+2
-3
main_verification.cpp
...lib3d/real_time_pose_estimation/src/main_verification.cpp
+0
-1
No files found.
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt
View file @
43301096
cmake_minimum_required
(
VERSION 2.8
)
project
(
PNP_DEMO
)
ADD_DEFINITIONS
(
-std=c++11
# Other flags
)
find_package
(
OpenCV REQUIRED
)
include_directories
(
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp
View file @
43301096
#include "CsvReader.h"
#include "Utils.h"
/** The default constructor of the CSV reader Class */
CsvReader
::
CsvReader
(
const
std
::
string
&
path
,
const
char
&
separator
){
...
...
@@ -27,8 +28,8 @@ void CsvReader::readPLY(std::vector<cv::Point3f> &list_vertex, std::vector<std::
{
getline
(
liness
,
tmp_str
,
_separator
);
getline
(
liness
,
n
);
if
(
tmp_str
==
"vertex"
)
num_vertex
=
StringTo
Number
(
n
);
if
(
tmp_str
==
"face"
)
num_triangles
=
StringTo
Number
(
n
);
if
(
tmp_str
==
"vertex"
)
num_vertex
=
StringTo
Int
(
n
);
if
(
tmp_str
==
"face"
)
num_triangles
=
StringTo
Int
(
n
);
}
if
(
tmp_str
==
"end_header"
)
end_header
=
true
;
}
...
...
@@ -45,9 +46,9 @@ void CsvReader::readPLY(std::vector<cv::Point3f> &list_vertex, std::vector<std::
getline
(
liness
,
z
);
cv
::
Point3f
tmp_p
;
tmp_p
.
x
=
StringTo
Number
(
x
);
tmp_p
.
y
=
StringTo
Number
(
y
);
tmp_p
.
z
=
StringTo
Number
(
z
);
tmp_p
.
x
=
StringTo
Int
(
x
);
tmp_p
.
y
=
StringTo
Int
(
y
);
tmp_p
.
z
=
StringTo
Int
(
z
);
list_vertex
.
push_back
(
tmp_p
);
count
++
;
...
...
@@ -67,9 +68,9 @@ void CsvReader::readPLY(std::vector<cv::Point3f> &list_vertex, std::vector<std::
getline
(
liness
,
id2
);
std
::
vector
<
int
>
tmp_triangle
(
3
);
tmp_triangle
[
0
]
=
StringTo
Number
(
id0
);
tmp_triangle
[
1
]
=
StringTo
Number
(
id1
);
tmp_triangle
[
2
]
=
StringTo
Number
(
id2
);
tmp_triangle
[
0
]
=
StringTo
Int
(
id0
);
tmp_triangle
[
1
]
=
StringTo
Int
(
id1
);
tmp_triangle
[
2
]
=
StringTo
Int
(
id2
);
list_triangles
.
push_back
(
tmp_triangle
);
count
++
;
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.h
View file @
43301096
...
...
@@ -5,7 +5,6 @@
#include <fstream>
#include <opencv2/core/core.hpp>
#include "Mesh.h"
using
namespace
std
;
using
namespace
cv
;
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp
View file @
43301096
#include <string>
#include "CsvWriter.h"
#include "Utils.h"
CsvWriter
::
CsvWriter
(
const
std
::
string
&
path
,
const
std
::
string
&
separator
){
_file
.
open
(
path
.
c_str
(),
std
::
ofstream
::
out
);
...
...
@@ -17,9 +17,9 @@ void CsvWriter::writeXYZ(const std::vector<cv::Point3f> &list_points3d)
std
::
string
x
,
y
,
z
;
for
(
unsigned
int
i
=
0
;
i
<
list_points3d
.
size
();
++
i
)
{
x
=
std
::
to_s
tring
(
list_points3d
[
i
].
x
);
y
=
std
::
to_s
tring
(
list_points3d
[
i
].
y
);
z
=
std
::
to_s
tring
(
list_points3d
[
i
].
z
);
x
=
FloatToS
tring
(
list_points3d
[
i
].
x
);
y
=
FloatToS
tring
(
list_points3d
[
i
].
y
);
z
=
FloatToS
tring
(
list_points3d
[
i
].
z
);
_file
<<
x
<<
_separator
<<
y
<<
_separator
<<
z
<<
std
::
endl
;
}
...
...
@@ -31,18 +31,18 @@ void CsvWriter::writeUVXYZ(const std::vector<cv::Point3f> &list_points3d, const
std
::
string
u
,
v
,
x
,
y
,
z
,
descriptor_str
;
for
(
int
i
=
0
;
i
<
list_points3d
.
size
();
++
i
)
{
u
=
std
::
to_s
tring
(
list_points2d
[
i
].
x
);
v
=
std
::
to_s
tring
(
list_points2d
[
i
].
y
);
x
=
std
::
to_s
tring
(
list_points3d
[
i
].
x
);
y
=
std
::
to_s
tring
(
list_points3d
[
i
].
y
);
z
=
std
::
to_s
tring
(
list_points3d
[
i
].
z
);
u
=
FloatToS
tring
(
list_points2d
[
i
].
x
);
v
=
FloatToS
tring
(
list_points2d
[
i
].
y
);
x
=
FloatToS
tring
(
list_points3d
[
i
].
x
);
y
=
FloatToS
tring
(
list_points3d
[
i
].
y
);
z
=
FloatToS
tring
(
list_points3d
[
i
].
z
);
_file
<<
u
<<
_separator
<<
v
<<
_separator
<<
x
<<
_separator
<<
y
<<
_separator
<<
z
;
for
(
int
j
=
0
;
j
<
32
;
++
j
)
{
std
::
cout
<<
descriptors
.
at
<
float
>
(
i
,
j
)
<<
std
::
endl
;
descriptor_str
=
std
::
to_s
tring
(
descriptors
.
at
<
float
>
(
i
,
j
));
descriptor_str
=
FloatToS
tring
(
descriptors
.
at
<
float
>
(
i
,
j
));
_file
<<
_separator
<<
descriptor_str
;
}
_file
<<
std
::
endl
;
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp
View file @
43301096
...
...
@@ -6,7 +6,6 @@
*/
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "PnPProblem.h"
#include "ModelRegistration.h"
...
...
@@ -30,9 +29,9 @@ double thickness_circ = -1;
// Draw a text with the question point
void
drawQuestion
(
cv
::
Mat
image
,
cv
::
Point3f
point
,
cv
::
Scalar
color
)
{
std
::
string
x
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point
.
x
);
std
::
string
y
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point
.
y
);
std
::
string
z
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point
.
z
);
std
::
string
x
=
IntToString
((
int
)
point
.
x
);
std
::
string
y
=
IntToString
((
int
)
point
.
y
);
std
::
string
z
=
IntToString
((
int
)
point
.
z
);
std
::
string
text
=
" Where is point ("
+
x
+
","
+
y
+
","
+
z
+
") ?"
;
cv
::
putText
(
image
,
text
,
cv
::
Point
(
25
,
50
),
fontFace
,
fontScale
,
color
,
thickness_font
,
8
);
...
...
@@ -53,7 +52,7 @@ void drawText2(cv::Mat image, std::string text, cv::Scalar color)
// Draw a text with the frame ratio
void
drawFPS
(
cv
::
Mat
image
,
double
fps
,
cv
::
Scalar
color
)
{
std
::
string
fps_str
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
fps
);
std
::
string
fps_str
=
IntToString
((
int
)
fps
);
std
::
string
text
=
fps_str
+
" FPS"
;
cv
::
putText
(
image
,
text
,
cv
::
Point
(
500
,
50
),
fontFace
,
fontScale
,
color
,
thickness_font
,
8
);
}
...
...
@@ -61,7 +60,7 @@ void drawFPS(cv::Mat image, double fps, cv::Scalar color)
// Draw a text with the frame ratio
void
drawConfidence
(
cv
::
Mat
image
,
double
confidence
,
cv
::
Scalar
color
)
{
std
::
string
conf_str
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
confidence
);
std
::
string
conf_str
=
IntToString
((
int
)
confidence
);
std
::
string
text
=
conf_str
+
" %"
;
cv
::
putText
(
image
,
text
,
cv
::
Point
(
500
,
75
),
fontFace
,
fontScale
,
color
,
thickness_font
,
8
);
}
...
...
@@ -69,8 +68,8 @@ void drawConfidence(cv::Mat image, double confidence, cv::Scalar color)
// Draw a text with the number of entered points
void
drawCounter
(
cv
::
Mat
image
,
int
n
,
int
n_max
,
cv
::
Scalar
color
)
{
std
::
string
n_str
=
boost
::
lexical_cast
<
std
::
string
>
(
n
);
std
::
string
n_max_str
=
boost
::
lexical_cast
<
std
::
string
>
(
n_max
);
std
::
string
n_str
=
IntToString
(
n
);
std
::
string
n_max_str
=
IntToString
(
n_max
);
std
::
string
text
=
n_str
+
" of "
+
n_max_str
+
" points"
;
cv
::
putText
(
image
,
text
,
cv
::
Point
(
500
,
50
),
fontFace
,
fontScale
,
color
,
thickness_font
,
8
);
}
...
...
@@ -86,10 +85,10 @@ void drawPoints(cv::Mat image, std::vector<cv::Point2f> &list_points_2d, std::ve
// Draw Selected points
cv
::
circle
(
image
,
point_2d
,
radius
,
color
,
-
1
,
lineType
);
std
::
string
idx
=
boost
::
lexical_cast
<
std
::
string
>
(
i
+
1
);
std
::
string
x
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point_3d
.
x
);
std
::
string
y
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point_3d
.
y
);
std
::
string
z
=
boost
::
lexical_cast
<
std
::
string
>
((
int
)
point_3d
.
z
);
std
::
string
idx
=
IntToString
(
i
+
1
);
std
::
string
x
=
IntToString
((
int
)
point_3d
.
x
);
std
::
string
y
=
IntToString
((
int
)
point_3d
.
y
);
std
::
string
z
=
IntToString
((
int
)
point_3d
.
z
);
std
::
string
text
=
"P"
+
idx
+
" ("
+
x
+
","
+
y
+
","
+
z
+
")"
;
point_2d
.
x
=
point_2d
.
x
+
10
;
...
...
@@ -273,3 +272,24 @@ cv::Mat euler2rot(const cv::Mat & euler)
return
rotationMatrix
;
}
int
StringToInt
(
const
std
::
string
&
Text
)
{
std
::
istringstream
ss
(
Text
);
int
result
;
return
ss
>>
result
?
result
:
0
;
}
std
::
string
FloatToString
(
float
Number
)
{
std
::
ostringstream
ss
;
ss
<<
Number
;
return
ss
.
str
();
}
std
::
string
IntToString
(
int
Number
)
{
std
::
ostringstream
ss
;
ss
<<
Number
;
return
ss
.
str
();
}
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.h
View file @
43301096
...
...
@@ -9,9 +9,9 @@
#define UTILS_H_
#include <iostream>
#include <time.h>
#include <cv.h>
#include "PnPProblem.h"
// Draw a text with the question point
void
drawQuestion
(
cv
::
Mat
image
,
cv
::
Point3f
point
,
cv
::
Scalar
color
);
...
...
@@ -53,6 +53,9 @@ cv::Mat quat2rot(cv::Mat &q);
cv
::
Mat
euler2rot
(
const
cv
::
Mat
&
euler
);
cv
::
Mat
rot2euler
(
const
cv
::
Mat
&
rotationMatrix
);
cv
::
Mat
quat2euler
(
const
cv
::
Mat
&
q
);
int
StringToInt
(
const
std
::
string
&
Text
);
std
::
string
FloatToString
(
float
Number
);
std
::
string
IntToString
(
int
Number
);
class
Timer
{
...
...
@@ -69,7 +72,4 @@ private:
double
tstart
,
tstop
,
ttime
;
};
#endif
/* UTILS_H_ */
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp
View file @
43301096
#include <iostream>
#include <time.h>
#include <boost/lexical_cast.hpp>
#include "cv.h"
#include "highgui.h"
...
...
@@ -238,7 +237,7 @@ int main(int argc, char *argv[])
// -- Step 3: Estimate the pose using RANSAC approach
pnp_detection
.
estimatePoseRANSAC
(
list_points3d_model_match
,
list_points2d_scene_match
,
cv
::
DLS
,
inliers_idx
,
cv
::
ITERATIVE
,
inliers_idx
,
iterationsCount
,
reprojectionError
,
confidence
);
// -- Step 4: Catch the inliers keypoints to draw
...
...
@@ -330,9 +329,9 @@ int main(int argc, char *argv[])
// Draw some debug text
int
inliers_int
=
inliers_idx
.
rows
;
int
outliers_int
=
good_matches
.
size
()
-
inliers_int
;
std
::
string
inliers_str
=
boost
::
lexical_cast
<
std
::
string
>
(
inliers_int
);
std
::
string
outliers_str
=
boost
::
lexical_cast
<
std
::
string
>
(
outliers_int
);
std
::
string
n
=
boost
::
lexical_cast
<
std
::
string
>
(
good_matches
.
size
());
std
::
string
inliers_str
=
IntToString
(
inliers_int
);
std
::
string
outliers_str
=
IntToString
(
outliers_int
);
std
::
string
n
=
IntToString
(
good_matches
.
size
());
std
::
string
text
=
"Found "
+
inliers_str
+
" of "
+
n
+
" matches"
;
std
::
string
text2
=
"Inliers: "
+
inliers_str
+
" - Outliers: "
+
outliers_str
;
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp
View file @
43301096
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "Mesh.h"
#include "Model.h"
...
...
@@ -261,12 +260,12 @@ int main(int argc, char *argv[])
std
::
vector
<
cv
::
Point2f
>
list_points_out
=
model
.
get_points2d_out
();
// Draw some debug text
std
::
string
num
=
boost
::
lexical_cast
<
std
::
string
>
(
list_points_in
.
size
());
std
::
string
num
=
IntToString
(
list_points_in
.
size
());
std
::
string
text
=
"There are "
+
num
+
" inliers"
;
drawText
(
img_vis
,
text
,
green
);
// Draw some debug text
num
=
boost
::
lexical_cast
<
std
::
string
>
(
list_points_out
.
size
());
num
=
IntToString
(
list_points_out
.
size
());
text
=
"There are "
+
num
+
" outliers"
;
drawText2
(
img_vis
,
text
,
red
);
...
...
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_verification.cpp
View file @
43301096
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "cv.h"
#include "highgui.h"
...
...
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