Subversion Repositories seema-scanner

Rev

Rev 36 | Rev 42 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36 Rev 41
Line 1... Line 1...
1
#include "SMReconstructionWorker.h"
1
#include "SMReconstructionWorker.h"
2
 
2
 
3
#include "CodecGrayCode.h"
3
#include "AlgorithmGrayCode.h"
4
#include "CodecPhaseShift.h"
4
#include "AlgorithmPhaseShift.h"
5
 
5
 
6
#include <QCoreApplication>
6
#include <QCoreApplication>
7
#include <QSettings>
7
#include <QSettings>
8
 
8
 
9
#include <iostream>
9
#include <iostream>
Line 18... Line 18...
18
    QSettings settings;
18
    QSettings settings;
19
 
19
 
20
    // Get current calibration
20
    // Get current calibration
21
    calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
21
    calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
22
 
22
 
23
    // Create decoder
23
    // Create Algorithm
24
    dir = (CodecDir)settings.value("pattern/direction", CodecDirHorizontal).toInt();
24
    dir = (CodingDir)settings.value("pattern/direction", CodingDirHorizontal).toInt();
25
    if(dir == CodecDirNone)
25
    if(dir == CodingDirNone)
26
        std::cerr << "SMCaptureWorker: invalid coding direction " << std::endl;
26
        std::cerr << "SMCaptureWorker: invalid coding direction " << std::endl;
27
 
27
 
28
    int resX = settings.value("projector/resX").toInt();
28
    int resX = settings.value("projector/resX").toInt();
29
    int resY = settings.value("projector/resY").toInt();
29
    int resY = settings.value("projector/resY").toInt();
30
    QString codec = settings.value("codec", "GrayCode").toString();
30
    QString codec = settings.value("codec", "GrayCode").toString();
31
    if(codec == "PhaseShift")
31
    if(codec == "PhaseShift")
32
        decoder = new DecoderPhaseShift(dir, resX, resY);
32
        algorithm = new AlgorithmPhaseShift(resX, resY, dir);
33
    else if(codec == "GrayCode")
33
    else if(codec == "GrayCode")
34
        decoder = new DecoderGrayCode(dir, resX, resY);
34
        algorithm = new AlgorithmGrayCode(resX, resY, dir);
35
    else
35
    else
36
        std::cerr << "SLScanWorker: invalid codec " << codec.toStdString() << std::endl;
36
        std::cerr << "SLScanWorker: invalid codec " << codec.toStdString() << std::endl;
37
 
37
 
38
 
38
 
39
    // Precompute lens correction maps
39
    // Precompute lens correction maps
Line 53... Line 53...
53
    time.start();
53
    time.start();
54
 
54
 
55
    // Get correspondences
55
    // Get correspondences
56
    std::vector<cv::Point2f> q0, q1;
56
    std::vector<cv::Point2f> q0, q1;
57
    std::vector<cv::Point3f> color;
57
    std::vector<cv::Point3f> color;
58
    decoder->getCorrespondences(frameSequence.frames0, frameSequence.frames0, q0, q1, color);
58
    algorithm->getCorrespondences(calibration, frameSequence.frames0, frameSequence.frames0, q0, q1, color);
59
 
59
 
60
    // Triangulate
60
    // Triangulate
61
    std::vector<cv::Point3f> Q;
61
    std::vector<cv::Point3f> Q;
62
    triangulate(q0, q1, Q);
62
    triangulate(q0, q1, Q);
63
 
63
 
Line 92... Line 92...
92
        reconstructPointCloud(frameSequences[i]);
92
        reconstructPointCloud(frameSequences[i]);
93
    }
93
    }
94
 
94
 
95
}
95
}
96
 
96
 
97
void SMReconstructionWorker::triangulate(std::vector<cv::Point2f>& q0, std::vector<cv::Point2f>& q1, std::vector<cv::Point3f> &Q){}
97
void SMReconstructionWorker::triangulate(std::vector<cv::Point2f>& q0, std::vector<cv::Point2f>& q1, std::vector<cv::Point3f> &Q){
-
 
98
 
-
 
99
    cv::Mat P0(3,4,CV_32F,cv::Scalar(0.0));
-
 
100
    cv::Mat(calibration.K0).copyTo(P0(cv::Range(0,3), cv::Range(0,3)));
-
 
101
 
-
 
102
    cv::Mat temp(3,4,CV_32F);
-
 
103
    cv::Mat(calibration.R1).copyTo(temp(cv::Range(0,3), cv::Range(0,3)));
-
 
104
    cv::Mat(calibration.T1).copyTo(temp(cv::Range(0,3), cv::Range(3,4)));
-
 
105
    cv::Mat P1 = cv::Mat(calibration.K1) * temp;
-
 
106
 
-
 
107
    cv::triangulatePoints(P0, P1, q0, q1, Q);
-
 
108
 
-
 
109
}
98
 
110
 
99
//void SMReconstructionWorker::triangulateFromUpVp(cv::Mat &up, cv::Mat &vp, cv::Mat &xyz){
111
//void SMReconstructionWorker::triangulateFromUpVp(cv::Mat &up, cv::Mat &vp, cv::Mat &xyz){
100
 
112
 
101
//    std::cerr << "WARNING! NOT FULLY IMPLEMENTED!" << std::endl;
113
//    std::cerr << "WARNING! NOT FULLY IMPLEMENTED!" << std::endl;
102
//    int N = up.rows * up.cols;
114
//    int N = up.rows * up.cols;