Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
vision_utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
algorithms
vision_utils
Commits
6d263b10
Commit
6d263b10
authored
7 years ago
by
Angel Santamaria-Navarro
Browse files
Options
Downloads
Patches
Plain Diff
WIP on trifocal tensor
parent
b82f3b21
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common_class/trifocaltensor.cpp
+62
-8
62 additions, 8 deletions
src/common_class/trifocaltensor.cpp
src/common_class/trifocaltensor.h
+8
-2
8 additions, 2 deletions
src/common_class/trifocaltensor.h
src/test/gtest_trifocaltensor.cpp
+7
-5
7 additions, 5 deletions
src/test/gtest_trifocaltensor.cpp
with
77 additions
and
15 deletions
src/common_class/trifocaltensor.cpp
+
62
−
8
View file @
6d263b10
...
...
@@ -44,13 +44,61 @@ void TrifocalTensor::fillTensor(const Eigen::VectorXd& tensorVector)
}
}
void
TrifocalTensor
::
computeTensor
(
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
)
void
TrifocalTensor
::
getRandomCandidates
(
const
int
&
min_points
,
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
,
Eigen
::
MatrixXd
&
l1
,
Eigen
::
MatrixXd
&
l2
,
Eigen
::
MatrixXd
&
l3
)
{
std
::
random_device
rd
;
//Will be used to obtain a seed for the random number engine
std
::
mt19937
gen
(
rd
());
//Standard mersenne_twister_engine seeded with rd()
std
::
uniform_int_distribution
<>
dis
(
0
,
min_points
-
1
);
Eigen
::
VectorXd
idx
=
Eigen
::
VectorXd
::
Zero
(
min_points
);
for
(
int
n
=
0
;
n
<
min_points
;
++
n
)
{
int
num
=
dis
(
gen
);
idx
(
n
)
=
num
;
for
(
int
ii
=
0
;
ii
<
n
;
++
ii
)
{
if
(
idx
(
ii
)
==
num
)
{
n
=
n
-
1
;
break
;
}
}
}
l1
=
Eigen
::
MatrixXd
::
Zero
(
min_points
,
3
);
l2
=
Eigen
::
MatrixXd
::
Zero
(
min_points
,
3
);
l3
=
Eigen
::
MatrixXd
::
Zero
(
min_points
,
3
);
for
(
int
ii
=
0
;
ii
<
l1
.
rows
();
++
ii
)
{
l1
.
row
(
ii
)
=
list1
.
row
(
idx
(
ii
));
l2
.
row
(
ii
)
=
list2
.
row
(
idx
(
ii
));
l3
.
row
(
ii
)
=
list3
.
row
(
idx
(
ii
));
}
}
bool
TrifocalTensor
::
computeTensor
(
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
)
{
//int min_points = list1.rows();
int
min_points
=
8
;
if
(
list1
.
rows
()
<
min_points
||
list2
.
rows
()
<
min_points
||
list3
.
rows
()
<
min_points
)
return
false
;
Eigen
::
MatrixXd
l1
(
min_points
,
3
),
l2
(
min_points
,
3
),
l3
(
min_points
,
3
);
getRandomCandidates
(
min_points
,
list1
,
list2
,
list3
,
l1
,
l2
,
l3
);
Eigen
::
MatrixXd
A
;
computeMatrixA
(
l
ist
1
,
l
ist
2
,
l
ist
3
,
A
);
computeMatrixA
(
l1
,
l2
,
l3
,
A
);
// resolve equation : A*t = 0 where t is unknown
Eigen
::
VectorXd
tensorVector
=
resolveEquationWithSVD
(
A
,
26
);
fillTensor
(
tensorVector
);
Eigen
::
VectorXd
tensorVector
;
if
(
resolveEquationWithSVD
(
A
,
tensorVector
)
)
{
fillTensor
(
tensorVector
);
return
true
;
}
else
return
false
;
}
void
TrifocalTensor
::
computeMatrixA
(
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
,
Eigen
::
MatrixXd
&
A
)
...
...
@@ -75,19 +123,25 @@ void TrifocalTensor::computeMatrixA(const Eigen::MatrixXd& list1, const Eigen::M
}
}
Eigen
::
VectorXd
TrifocalTensor
::
resolveEquationWithSVD
(
Eigen
::
MatrixXd
&
A
,
size_t
indexOfLastColumnOfV
)
bool
TrifocalTensor
::
resolveEquationWithSVD
(
Eigen
::
MatrixXd
&
A
,
Eigen
::
VectorXd
&
tensorVector
)
{
Eigen
::
JacobiSVD
<
Eigen
::
MatrixXd
>
svd
(
A
,
Eigen
::
ComputeThinU
|
Eigen
::
ComputeThinV
);
// Ensure that a poor choice of points are not selected to compute the Trifocal Tensor.
// The check is based on the condition number of the matrices involved in computing the trifocal tensor
double
cond
=
svd
.
singularValues
()(
0
)
/
svd
.
singularValues
()(
svd
.
singularValues
().
size
()
-
1
);
if
(
std
::
isnan
(
cond
)
||
cond
<
1e-6
)
return
false
;
const
Eigen
::
MatrixXd
U
=
svd
.
matrixU
();
const
Eigen
::
VectorXd
D_diag
=
svd
.
singularValues
();
Eigen
::
MatrixXd
V
=
svd
.
matrixV
();
Eigen
::
VectorXd
tensorVector
;
tensorVector
.
Zero
(
27
);
tensorVector
=
V
.
col
(
indexOfLastColumnOfV
);
tensorVector
=
V
.
col
(
26
);
return
t
ensorVector
;
return
t
rue
;
}
...
...
This diff is collapsed.
Click to expand it.
src/common_class/trifocaltensor.h
+
8
−
2
View file @
6d263b10
...
...
@@ -3,6 +3,8 @@
#include
<Eigen/Dense>
#include
<random>
// vision utils includes
#include
"../vision_utils.h"
...
...
@@ -29,7 +31,7 @@ public:
/**
* \brief Compute trifocal tensor
*/
void
computeTensor
(
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
);
bool
computeTensor
(
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
);
/**
* \brief Compute the coordinates of the point p3 on third img corresponding to p1 and p2 of others images
...
...
@@ -58,7 +60,7 @@ private:
/**
* \brief Resolve equation by finding tensor in A*tensor = 0 excluding the solution t = 0 with SVD decomposition
*/
Eigen
::
VectorXd
resolveEquationWithSVD
(
Eigen
::
MatrixXd
&
A
,
size_t
indexOfLastColumnOfV
);
bool
resolveEquationWithSVD
(
Eigen
::
MatrixXd
&
A
,
Eigen
::
VectorXd
&
tensorVector
);
/**
* \brief Fill elements of the tensor with the solution found
...
...
@@ -70,6 +72,10 @@ private:
*/
void
computeMatrixB
(
const
Eigen
::
Vector3d
&
p1
,
const
Eigen
::
Vector3d
&
p2
,
Eigen
::
MatrixXd
&
B
,
Eigen
::
VectorXd
&
b
);
/**
* \brief Get random candidates
*/
void
getRandomCandidates
(
const
int
&
min_points
,
const
Eigen
::
MatrixXd
&
list1
,
const
Eigen
::
MatrixXd
&
list2
,
const
Eigen
::
MatrixXd
&
list3
,
Eigen
::
MatrixXd
&
l1
,
Eigen
::
MatrixXd
&
l2
,
Eigen
::
MatrixXd
&
l3
);
};
}
/* namespace vision_utils */
...
...
This diff is collapsed.
Click to expand it.
src/test/gtest_trifocaltensor.cpp
+
7
−
5
View file @
6d263b10
...
...
@@ -260,7 +260,8 @@ TEST(TrifocalTensor, ComputeTensorSynthetic)
list3
.
row
(
8
)
<<
247.6911
,
244.6778
,
1.0
;
vision_utils
::
TrifocalTensor
tensor
;
tensor
.
computeTensor
(
list1
,
list2
,
list3
);
bool
tensor_ok
=
tensor
.
computeTensor
(
list1
,
list2
,
list3
);
ASSERT_TRUE
(
tensor_ok
);
KeyPointVector
kpts_tensor_in3
;
for
(
int
ii
=
0
;
ii
<
list1
.
rows
();
++
ii
)
...
...
@@ -274,9 +275,9 @@ TEST(TrifocalTensor, ComputeTensorSynthetic)
for
(
int
ii
=
0
;
ii
<
kpts_tensor_in3
.
size
();
++
ii
)
{
//
std::cout << "TODO: debug tensor with gtest_trifocaltensor" << std::endl;
//
std::cout << std::sqrt(std::pow(kpts_tensor_in3[ii].pt.x-list3(ii,0),2) + std::pow(kpts_tensor_in3[ii].pt.y-list3(ii,1),2)) << std::endl;
ASSERT_TRUE
(
std
::
sqrt
(
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
x
-
list3
(
ii
,
0
),
2
)
+
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
y
-
list3
(
ii
,
1
),
2
))
<=
1e-
3
);
std
::
cout
<<
"TODO: debug tensor with gtest_trifocaltensor"
<<
std
::
endl
;
std
::
cout
<<
std
::
sqrt
(
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
x
-
list3
(
ii
,
0
),
2
)
+
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
y
-
list3
(
ii
,
1
),
2
))
<<
std
::
endl
;
ASSERT_TRUE
(
std
::
sqrt
(
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
x
-
list3
(
ii
,
0
),
2
)
+
std
::
pow
(
kpts_tensor_in3
[
ii
].
pt
.
y
-
list3
(
ii
,
1
),
2
))
<=
1e-
1
);
}
}
...
...
@@ -413,7 +414,8 @@ TEST(TrifocalTensor, ComputeTensorReal)
Eigen
::
MatrixXd
list3
=
vision_utils
::
KeyPointVecToEigenMat
(
kpts_good_in3
);
vision_utils
::
TrifocalTensor
tensor
;
tensor
.
computeTensor
(
list1
,
list2
,
list3
);
bool
tensor_ok
=
tensor
.
computeTensor
(
list1
,
list2
,
list3
);
ASSERT_TRUE
(
tensor_ok
);
KeyPointVector
kpts_tensor_in3
;
for
(
int
ii
=
0
;
ii
<
list1
.
rows
();
++
ii
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment