Subversion Repositories seema-scanner

Rev

Rev 1 | Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 31
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 fit two sets of corresponding transformation data.
-
 
12
// 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
-
 
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){
-
 
15
// NOT DEBUGGED!
-
 
16
    int N = R.size();
-
 
17
    assert(N == R_mark.size());
-
 
18
    assert(N == t.size());
-
 
19
    assert(N == t_mark.size());
-
 
20
 
-
 
21
    // Mean translations
-
 
22
    cv::Vec3f t_mean;
-
 
23
    cv::Vec3f t_mark_mean;
-
 
24
    for(int i=0; i<N; i++){
-
 
25
        t_mean += 1.0/N * t[i];
-
 
26
        t_mark_mean += 1.0/N * t_mark[i];
-
 
27
    }
-
 
28
 
-
 
29
    // Data with mean adjusted translations
-
 
30
    cv::Mat X_bar(3, 4*N, CV_32F);
-
 
31
    cv::Mat X_mark_bar(3, 4*N, CV_32F);
-
 
32
    for(int i=0; i<N; i++){
-
 
33
        // ASSIGNEMENTS?!
-
 
34
        X_bar.colRange(i*4,i*4+3) = cv::Mat(R[i]);
-
 
35
        X_bar.col(i*4+3) = cv::Mat(t[i] - t_mean);
-
 
36
        X_mark_bar.colRange(i*4,i*4+3) = cv::Mat(R_mark[i]);
-
 
37
        X_mark_bar.col(i*4+3) = cv::Mat(t_mark[i] - t_mark_mean);
-
 
38
    }
-
 
39
 
-
 
40
    // SVD
-
 
41
    cv::Matx33f W, U, VT;
-
 
42
    cv::SVDecomp(X_bar*X_mark_bar.t(), W, U, VT);
-
 
43
 
-
 
44
    cv::Matx33f D = cv::Matx33f::eye();
-
 
45
    if(cv::determinant(VT*U) < 0)
-
 
46
        D(3,3) = -1;
-
 
47
 
-
 
48
    // Best rotation
-
 
49
    Omega = VT*D*U;
-
 
50
 
-
 
51
    // Best translation
-
 
52
    tau = t_mark_mean - Omega*t_mean;
-
 
53
 
-
 
54
}
-
 
55
 
11
// Forward distortion of points. The inverse of the undistortion in cv::initUndistortRectifyMap().
56
// Forward distortion of points. The inverse of the undistortion in cv::initUndistortRectifyMap().
12
// Inspired by Pascal Thomet, http://code.opencv.org/issues/1387#note-11
57
// Inspired by Pascal Thomet, http://code.opencv.org/issues/1387#note-11
13
// Convention for distortion parameters: http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/parameters.html
58
// Convention for distortion parameters: http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/parameters.html
14
void initDistortMap(const cv::Matx33f cameraMatrix, const cv::Vec<float, 5> distCoeffs, const cv::Size size, cv::Mat &map1, cv::Mat &map2){
59
void initDistortMap(const cv::Matx33f cameraMatrix, const cv::Vec<float, 5> distCoeffs, const cv::Size size, cv::Mat &map1, cv::Mat &map2){
15
 
60