Line 6... |
Line 6... |
6 |
|
6 |
|
7 |
#include <stdio.h>
|
7 |
#include <stdio.h>
|
8 |
|
8 |
|
9 |
namespace cvtools{
|
9 |
namespace cvtools{
|
10 |
|
10 |
|
- |
|
11 |
// Function to solve the hand-eye (or eye-in-hand) calibration problem.
|
- |
|
12 |
// Finds [Omega | tau], to minimize ||[R_mark | t_mark][Omega | tau] - [Omega | tau][R | t]||^2
|
- |
|
13 |
// Algorithm according to Tsai, Lenz, A new technique for fully autonomous and efficient 3d robotics hand-eye calibration
|
- |
|
14 |
// DTU, 2014, Jakob Wilm
|
- |
|
15 |
void handEyeCalibrationTsai(const std::vector<cv::Matx33f> R, const std::vector<cv::Vec3f> t, const std::vector<cv::Matx33f> R_mark, const std::vector<cv::Vec3f> t_mark, cv::Matx33f &Omega, cv::Vec3f &tau){
|
- |
|
16 |
// NOT DEBUGGED!
|
- |
|
17 |
int N = R.size();
|
- |
|
18 |
assert(N == R_mark.size());
|
- |
|
19 |
assert(N == t.size());
|
- |
|
20 |
assert(N == t_mark.size());
|
- |
|
21 |
|
- |
|
22 |
// construct equations for rotation
|
- |
|
23 |
cv::Mat A(3*N, 3, CV_32F);
|
- |
|
24 |
cv::Mat b(3*N, 1, CV_32F);
|
- |
|
25 |
for(int i=0; i<N; i++){
|
- |
|
26 |
// angle axis representations
|
- |
|
27 |
cv::Vec3f rot;
|
- |
|
28 |
cv::Vec3f rot_mark;
|
- |
|
29 |
cv::Rodrigues(R[i], rot);
|
- |
|
30 |
cv::Rodrigues(R_mark[i], rot_mark);
|
- |
|
31 |
|
- |
|
32 |
cv::Vec3f P = 2.0*sin(cv::norm(rot)/2.0)*cv::normalize(rot);
|
- |
|
33 |
cv::Vec3f P_mark = 2.0*sin(cv::norm(rot_mark)/2.0)*cv::normalize(rot_mark);
|
- |
|
34 |
|
- |
|
35 |
cv::Vec3f sum = P+P_mark;
|
- |
|
36 |
cv::Mat crossProduct = (cv::Mat_<float>(3,3) << 0.0, -sum(2), sum(1), sum(2), 0.0, -sum(0), -sum(1), sum(0), 0.0);
|
- |
|
37 |
|
- |
|
38 |
crossProduct.copyTo(A.rowRange(i*3, i*3+3));
|
- |
|
39 |
|
- |
|
40 |
cv::Mat(P-P_mark).copyTo(b.rowRange(i*3, i*3+3));
|
- |
|
41 |
}
|
- |
|
42 |
|
- |
|
43 |
// solve for rotation
|
- |
|
44 |
cv::Vec<float, 9> P_prime;
|
- |
|
45 |
cv::solve(A, b, P_prime);
|
- |
|
46 |
cv::Vec<float, 9> P = 2.0*P_prime/(cv::sqrt(1.0 + cv::norm(P_prime)*cv::norm(P_prime)));
|
- |
|
47 |
float nP = cv::norm(P);
|
- |
|
48 |
cv::Mat crossProduct = (cv::Mat_<float>(3,3) << 0.0, -P(2), P(1), P(2), 0.0, -P(0), -P(1), P(0), 0.0);
|
- |
|
49 |
cv::Mat OmegaMat = (1.0-nP*nP/2.0)*cv::Mat::eye(3,3,CV_32F) + 0.5*(cv::Mat(P)*cv::Mat(P).t() + cv::sqrt(4.0 - nP*nP)*crossProduct);
|
- |
|
50 |
Omega = cv::Matx33f(OmegaMat);
|
- |
|
51 |
|
- |
|
52 |
// construct equations for translation
|
- |
|
53 |
A.setTo(0.0);
|
- |
|
54 |
b.setTo(0.0);
|
- |
|
55 |
for(int i=0; i<N; i++){
|
- |
|
56 |
|
- |
|
57 |
cv::Mat diff = cv::Mat(R[i]) - cv::Mat::eye(3, 3, CV_32F);
|
- |
|
58 |
diff.copyTo(A.rowRange(i*3, i*3+3));
|
- |
|
59 |
|
- |
|
60 |
cv::Mat diff_mark = cv::Mat(Omega*R_mark[i] - R[i]);
|
- |
|
61 |
diff_mark.copyTo(b.rowRange(i*3, i*3+3));
|
- |
|
62 |
}
|
- |
|
63 |
|
- |
|
64 |
// solve for translation
|
- |
|
65 |
cv::solve(A, b, tau);
|
- |
|
66 |
}
|
- |
|
67 |
|
11 |
// Function to fit two sets of corresponding transformation data.
|
68 |
// Function to fit two sets of corresponding pose data.
|
- |
|
69 |
// Finds [Omega | tau], to minimize ||[R_mark | t_mark] - [Omega | tau][R | t]||^2
|
12 |
// Algorithm and notation according to Mili Shah, Comparing two sets of corresponding six degree of freedom data, CVIU 2011.
|
70 |
// Algorithm and notation according to Mili Shah, Comparing two sets of corresponding six degree of freedom data, CVIU 2011.
|
13 |
// DTU, 2013, Oline V. Olesen, Jakob Wilm
|
71 |
// DTU, 2013, Oline V. Olesen, Jakob Wilm
|
14 |
void fitSixDofData(const std::vector<cv::Matx33f> R, const std::vector<cv::Vec3f> t, const std::vector<cv::Matx33f> R_mark, const std::vector<cv::Vec3f> t_mark, cv::Matx33f &Omega, cv::Vec3f &tau){
|
72 |
void fitSixDofData(const std::vector<cv::Matx33f> R, const std::vector<cv::Vec3f> t, const std::vector<cv::Matx33f> R_mark, const std::vector<cv::Vec3f> t_mark, cv::Matx33f &Omega, cv::Vec3f &tau){
|
15 |
// NOT DEBUGGED!
|
- |
|
- |
|
73 |
|
16 |
int N = R.size();
|
74 |
int N = R.size();
|
17 |
assert(N == R_mark.size());
|
75 |
assert(N == R_mark.size());
|
18 |
assert(N == t.size());
|
76 |
assert(N == t.size());
|
19 |
assert(N == t_mark.size());
|
77 |
assert(N == t_mark.size());
|
20 |
|
78 |
|