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
b6b0c2aa
Commit
b6b0c2aa
authored
Jul 30, 2014
by
edgarriba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MACRO for EIGEN libraries
parent
4ddc6a4a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
dls.cpp
modules/calib3d/src/dls.cpp
+9
-10
solvepnp.cpp
modules/calib3d/src/solvepnp.cpp
+8
-7
No files found.
modules/calib3d/src/dls.cpp
View file @
b6b0c2aa
...
@@ -2,30 +2,30 @@
...
@@ -2,30 +2,30 @@
#include "dls.h"
#include "dls.h"
#include <iostream>
#include <iostream>
#include <fstream>
/*
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN
# if defined __GNUC__ && defined __APPLE__
# if defined __GNUC__ && defined __APPLE__
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wshadow"
# endif
# endif
# include <Eigen/Core>
# include <Eigen/Core>
# include <Eigen/Eigenvalues>
# include "opencv2/core/eigen.hpp"
# include "opencv2/core/eigen.hpp"
#endif
#endif
*/
#include <Eigen/Eigenvalues>
#include <Eigen/Core>
//#include <Eigen/Eigenvalues>
//#include <Eigen/Core>
using
namespace
std
;
using
namespace
std
;
dls
::
dls
(
const
cv
::
Mat
&
opoints
,
const
cv
::
Mat
&
ipoints
)
dls
::
dls
(
const
cv
::
Mat
&
opoints
,
const
cv
::
Mat
&
ipoints
)
{
{
N
=
std
::
max
(
opoints
.
checkVector
(
3
,
CV_32F
),
opoints
.
checkVector
(
3
,
CV_64F
));
N
=
std
::
max
(
opoints
.
checkVector
(
3
,
CV_32F
),
opoints
.
checkVector
(
3
,
CV_64F
));
p
=
cv
::
Mat
(
3
,
N
,
CV_64F
);
p
=
cv
::
Mat
(
3
,
N
,
CV_64F
);
z
=
cv
::
Mat
(
3
,
N
,
CV_64F
);
z
=
cv
::
Mat
(
3
,
N
,
CV_64F
);
cost__
=
std
::
numeric_limits
<
double
>::
infinity
()
;
cost__
=
9999
;
f1coeff
.
resize
(
21
);
f1coeff
.
resize
(
21
);
f2coeff
.
resize
(
21
);
f2coeff
.
resize
(
21
);
...
@@ -117,7 +117,6 @@ bool dls::compute_pose(cv::Mat& R, cv::Mat& t)
...
@@ -117,7 +117,6 @@ bool dls::compute_pose(cv::Mat& R, cv::Mat& t)
void
dls
::
run_kernel
(
const
cv
::
Mat
&
pp
)
void
dls
::
run_kernel
(
const
cv
::
Mat
&
pp
)
{
{
cv
::
Mat
Mtilde
(
27
,
27
,
CV_64F
);
cv
::
Mat
Mtilde
(
27
,
27
,
CV_64F
);
cv
::
Mat
D
=
cv
::
Mat
::
zeros
(
9
,
9
,
CV_64F
);
cv
::
Mat
D
=
cv
::
Mat
::
zeros
(
9
,
9
,
CV_64F
);
build_coeff_matrix
(
pp
,
Mtilde
,
D
);
build_coeff_matrix
(
pp
,
Mtilde
,
D
);
...
@@ -125,7 +124,6 @@ void dls::run_kernel(const cv::Mat& pp)
...
@@ -125,7 +124,6 @@ void dls::run_kernel(const cv::Mat& pp)
cv
::
Mat
eigenval_r
,
eigenval_i
,
eigenvec_r
,
eigenvec_i
;
cv
::
Mat
eigenval_r
,
eigenval_i
,
eigenvec_r
,
eigenvec_i
;
compute_eigenvec
(
Mtilde
,
eigenval_r
,
eigenval_i
,
eigenvec_r
,
eigenvec_i
);
compute_eigenvec
(
Mtilde
,
eigenval_r
,
eigenval_i
,
eigenvec_r
,
eigenvec_i
);
/*
/*
* Now check the solutions
* Now check the solutions
*/
*/
...
@@ -146,8 +144,6 @@ void dls::run_kernel(const cv::Mat& pp)
...
@@ -146,8 +144,6 @@ void dls::run_kernel(const cv::Mat& pp)
cv
::
Mat
V_k
;
cv
::
solve
(
V_kB
.
t
(),
V_kA
.
t
(),
V_k
);
// A/B = B'\A'
cv
::
Mat
V_k
;
cv
::
solve
(
V_kB
.
t
(),
V_kA
.
t
(),
V_k
);
// A/B = B'\A'
cv
::
Mat
(
V_k
.
t
()).
copyTo
(
eigenvec_r
.
col
(
k
)
);
cv
::
Mat
(
V_k
.
t
()).
copyTo
(
eigenvec_r
.
col
(
k
)
);
// TODO: check imaginari part to filter solutions
//if (imag(V(2,k)) == 0)
//if (imag(V(2,k)) == 0)
const
double
epsilon
=
1e-4
;
const
double
epsilon
=
1e-4
;
if
(
eigenval_i
.
at
<
double
>
(
k
,
0
)
>=
-
epsilon
&&
eigenval_i
.
at
<
double
>
(
k
,
0
)
<=
epsilon
)
if
(
eigenval_i
.
at
<
double
>
(
k
,
0
)
>=
-
epsilon
&&
eigenval_i
.
at
<
double
>
(
k
,
0
)
<=
epsilon
)
...
@@ -230,6 +226,7 @@ void dls::run_kernel(const cv::Mat& pp)
...
@@ -230,6 +226,7 @@ void dls::run_kernel(const cv::Mat& pp)
cost_
.
push_back
(
cost_valid
);
cost_
.
push_back
(
cost_valid
);
}
}
}
}
}
}
void
dls
::
build_coeff_matrix
(
const
cv
::
Mat
&
pp
,
cv
::
Mat
&
Mtilde
,
cv
::
Mat
&
D
)
void
dls
::
build_coeff_matrix
(
const
cv
::
Mat
&
pp
,
cv
::
Mat
&
Mtilde
,
cv
::
Mat
&
D
)
...
@@ -287,6 +284,7 @@ void dls::compute_eigenvec(const cv::Mat& Mtilde, cv::Mat& eigenval_real, cv::Ma
...
@@ -287,6 +284,7 @@ void dls::compute_eigenvec(const cv::Mat& Mtilde, cv::Mat& eigenval_real, cv::Ma
{
{
// EIGENVALUES AND EIGENVECTORS
// EIGENVALUES AND EIGENVECTORS
#ifdef HAVE_EIGEN
Eigen
::
MatrixXd
Mtilde_eig
,
zeros_eig
;
Eigen
::
MatrixXd
Mtilde_eig
,
zeros_eig
;
cv
::
cv2eigen
(
Mtilde
,
Mtilde_eig
);
cv
::
cv2eigen
(
Mtilde
,
Mtilde_eig
);
cv
::
cv2eigen
(
cv
::
Mat
::
zeros
(
27
,
27
,
CV_64F
),
zeros_eig
);
cv
::
cv2eigen
(
cv
::
Mat
::
zeros
(
27
,
27
,
CV_64F
),
zeros_eig
);
...
@@ -307,6 +305,7 @@ void dls::compute_eigenvec(const cv::Mat& Mtilde, cv::Mat& eigenval_real, cv::Ma
...
@@ -307,6 +305,7 @@ void dls::compute_eigenvec(const cv::Mat& Mtilde, cv::Mat& eigenval_real, cv::Ma
cv
::
eigen2cv
(
eigval_imag
,
eigenval_imag
);
cv
::
eigen2cv
(
eigval_imag
,
eigenval_imag
);
cv
::
eigen2cv
(
eigvec_real
,
eigenvec_real
);
cv
::
eigen2cv
(
eigvec_real
,
eigenvec_real
);
cv
::
eigen2cv
(
eigvec_imag
,
eigenvec_imag
);
cv
::
eigen2cv
(
eigvec_imag
,
eigenvec_imag
);
#endif
}
}
...
...
modules/calib3d/src/solvepnp.cpp
View file @
b6b0c2aa
...
@@ -49,11 +49,6 @@
...
@@ -49,11 +49,6 @@
#include <iostream>
#include <iostream>
using
namespace
cv
;
using
namespace
cv
;
void
MatrixSize
(
const
cv
::
Mat
&
mat
)
{
cout
<<
mat
.
rows
<<
"x"
<<
mat
.
cols
<<
endl
;
}
bool
cv
::
solvePnP
(
InputArray
_opoints
,
InputArray
_ipoints
,
bool
cv
::
solvePnP
(
InputArray
_opoints
,
InputArray
_ipoints
,
InputArray
_cameraMatrix
,
InputArray
_distCoeffs
,
InputArray
_cameraMatrix
,
InputArray
_distCoeffs
,
OutputArray
_rvec
,
OutputArray
_tvec
,
bool
useExtrinsicGuess
,
int
flags
)
OutputArray
_rvec
,
OutputArray
_tvec
,
bool
useExtrinsicGuess
,
int
flags
)
...
@@ -101,19 +96,25 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
...
@@ -101,19 +96,25 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
}
}
else
if
(
flags
==
DLS
)
else
if
(
flags
==
DLS
)
{
{
bool
result
=
false
;
#ifdef HAVE_EIGEN
cv
::
Mat
undistortedPoints
;
cv
::
Mat
undistortedPoints
;
cv
::
undistortPoints
(
ipoints
,
undistortedPoints
,
cameraMatrix
,
distCoeffs
);
cv
::
undistortPoints
(
ipoints
,
undistortedPoints
,
cameraMatrix
,
distCoeffs
);
dls
PnP
(
opoints
,
undistortedPoints
);
dls
PnP
(
opoints
,
undistortedPoints
);
cv
::
Mat
R
,
rvec
=
_rvec
.
getMat
(),
tvec
=
_tvec
.
getMat
();
cv
::
Mat
R
,
rvec
=
_rvec
.
getMat
(),
tvec
=
_tvec
.
getMat
();
bool
result
=
PnP
.
compute_pose
(
R
,
tvec
);
result
=
PnP
.
compute_pose
(
R
,
tvec
);
if
(
result
)
if
(
result
)
cv
::
Rodrigues
(
R
,
rvec
);
cv
::
Rodrigues
(
R
,
rvec
);
#else
std
::
cout
<<
"EIGEN library needed for DLS"
<<
std
::
endl
;
#endif
return
result
;
return
result
;
}
}
else
else
CV_Error
(
CV_StsBadArg
,
"The flags argument must be one of CV_ITERATIVE, CV_P3P
or CV_EPNP
"
);
CV_Error
(
CV_StsBadArg
,
"The flags argument must be one of CV_ITERATIVE, CV_P3P
, CV_EPNP or CV_DLS
"
);
return
false
;
return
false
;
}
}
...
...
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