Subversion Repositories seema-scanner

Rev

Rev 24 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24 Rev 25
1
#include "SMSMTriangulator.h"
1
#include "SMTriangulator.h"
2
 
2
 
3
#include <QCoreApplication>
3
#include <QCoreApplication>
4
#include <QSettings>
4
#include <QSettings>
5
 
5
 
6
#include <iostream>
6
#include <iostream>
7
#include <opencv2/opencv.hpp>
7
#include <opencv2/opencv.hpp>
8
 
8
 
9
#include <pcl/filters/statistical_outlier_removal.h>
9
#include <pcl/filters/statistical_outlier_removal.h>
10
#include <pcl/io/pcd_io.h>
10
#include <pcl/io/pcd_io.h>
11
 
11
 
12
void SMSMTriangulator::setup(){
-
 
13
 
12
 
14
    // Initialize SMTriangulator with calibration
13
SMTriangulator::SMTriangulator(){
15
    calibration = new SMCalibrationParams;
-
 
16
    calibration->load("calibration.yml");
-
 
17
    SMTriangulator = new SMTriangulator(*calibration, frameWidth, frameHeight);
-
 
18
 
14
 
19
    QSettings settings("SLStudio");
15
    // Precompute lens correction maps
20
    writeToDisk = settings.value("writeToDisk/pointclouds",false).toBool();
16
    cv::Mat eye = cv::Mat::eye(3, 3, CV_32F);
-
 
17
    cv::initUndistortRectifyMap(calibration.K0, calibration.k0, eye, calibration.K0, cv::Size(calibration.frameWidth, calibration.frameHeight), CV_32FC1, lensMap1, lensMap2);
21
 
18
 
-
 
19
    //cv::Mat map1, map2;
-
 
20
    //cv::normalize(lensMap1, map1, 0, 255, cv::NORM_MINMAX, CV_8U);
-
 
21
    //cv::normalize(lensMap2, map2, 0, 255, cv::NORM_MINMAX, CV_8U);
-
 
22
    //cv::imwrite("map1.png", map1);
-
 
23
    //cv::imwrite("map2.png", map2);
22
}
24
}
23
 
25
 
24
 
-
 
25
void SMSMTriangulator::triangulatePointCloud(cv::Mat up, cv::Mat vp, cv::Mat mask, cv::Mat shading){
26
void SMTriangulator::triangulatePointCloud(cv::Mat up, cv::Mat vp, cv::Mat mask, cv::Mat shading){
26
 
27
 
27
    time.start();
28
    time.start();
28
 
29
 
29
    // Reconstruct point cloud
30
    // Reconstruct point cloud
30
    cv::Mat pointCloud;
31
    cv::Mat pointCloud;
31
    cv::Mat empty;
32
    cv::Mat empty;
32
    SMTriangulator->triangulate(up, vp, mask, shading, pointCloud);
33
    triangulate(up, vp, mask, shading, pointCloud);
33
 
34
 
34
    std::vector<cv::Mat> xyz;
35
    std::vector<cv::Mat> xyz;
35
    cv::split(pointCloud, xyz);
36
    cv::split(pointCloud, xyz);
36
//    emit imshow("x", xyz[0], 1400, 100);
37
//    emit imshow("x", xyz[0], 1400, 100);
37
//    emit imshow("y", xyz[1], 1400, 450);
38
//    emit imshow("y", xyz[1], 1400, 450);
38
//    emit imshow("z", xyz[2], 1400, 800);
39
//    emit imshow("z", xyz[2], 1400, 800);
39
 
40
 
40
    // Convert point cloud to PCL format
41
    // Convert point cloud to PCL format
41
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloudPCL(new pcl::PointCloud<pcl::PointXYZRGB>);
42
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloudPCL(new pcl::PointCloud<pcl::PointXYZRGB>);
42
 
43
 
43
    // Interprete as organized point cloud
44
    // Interprete as organized point cloud
44
    pointCloudPCL->width = pointCloud.cols;
45
    pointCloudPCL->width = pointCloud.cols;
45
    pointCloudPCL->height = pointCloud.rows;
46
    pointCloudPCL->height = pointCloud.rows;
46
    pointCloudPCL->is_dense = false;
47
    pointCloudPCL->is_dense = false;
47
 
48
 
48
    pointCloudPCL->points.resize(pointCloud.rows*pointCloud.cols);
49
    pointCloudPCL->points.resize(pointCloud.rows*pointCloud.cols);
49
 
50
 
50
    //    for(int col=0; col<pointCloud.cols; col++){
51
    //    for(int col=0; col<pointCloud.cols; col++){
51
    //        for(int row=0; row<pointCloud.rows; row++){
52
    //        for(int row=0; row<pointCloud.rows; row++){
52
    //            const cv::Vec3f pnt = pointCloud.at<cv::Vec3f>(row,col);
53
    //            const cv::Vec3f pnt = pointCloud.at<cv::Vec3f>(row,col);
53
    //            unsigned char shade = shading.at<unsigned char>(row,col);
54
    //            unsigned char shade = shading.at<unsigned char>(row,col);
54
    //            pcl::PointXYZRGBRGB point;
55
    //            pcl::PointXYZRGBRGB point;
55
    //            point.x = pnt[0]; point.y = pnt[1]; point.z = pnt[2];
56
    //            point.x = pnt[0]; point.y = pnt[1]; point.z = pnt[2];
56
    //            point.r = shade; point.g = shade; point.b = shade;
57
    //            point.r = shade; point.g = shade; point.b = shade;
57
    //            pointCloudPCL->at(col, row) = point;
58
    //            pointCloudPCL->at(col, row) = point;
58
    //        }
59
    //        }
59
    //    }
60
    //    }
60
 
61
 
61
    // stack xyz data
62
    // stack xyz data
62
    std::vector<cv::Mat> pointCloudChannels;
63
    std::vector<cv::Mat> pointCloudChannels;
63
    pointCloudChannels.push_back(xyz[0]);
64
    pointCloudChannels.push_back(xyz[0]);
64
    pointCloudChannels.push_back(xyz[1]);
65
    pointCloudChannels.push_back(xyz[1]);
65
    pointCloudChannels.push_back(xyz[2]);
66
    pointCloudChannels.push_back(xyz[2]);
66
 
67
 
67
    // 4 byte padding
68
    // 4 byte padding
68
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
69
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
69
 
70
 
70
    // triple uchar color information
71
    // triple uchar color information
71
    std::vector<cv::Mat> rgb;
72
    std::vector<cv::Mat> rgb;
72
    rgb.push_back(shading);
73
    rgb.push_back(shading);
73
    rgb.push_back(shading);
74
    rgb.push_back(shading);
74
    rgb.push_back(shading);
75
    rgb.push_back(shading);
75
    rgb.push_back(cv::Mat::zeros(shading.size(), CV_8U));
76
    rgb.push_back(cv::Mat::zeros(shading.size(), CV_8U));
76
 
77
 
77
    cv::Mat rgb8UC4;
78
    cv::Mat rgb8UC4;
78
    cv::merge(rgb, rgb8UC4);
79
    cv::merge(rgb, rgb8UC4);
79
 
80
 
80
    cv::Mat rgb32F(rgb8UC4.size(), CV_32F, rgb8UC4.data);
81
    cv::Mat rgb32F(rgb8UC4.size(), CV_32F, rgb8UC4.data);
81
 
82
 
82
    pointCloudChannels.push_back(rgb32F);
83
    pointCloudChannels.push_back(rgb32F);
83
 
84
 
84
    // 12 bytes padding
85
    // 12 bytes padding
85
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
86
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
86
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
87
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
87
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
88
    pointCloudChannels.push_back(cv::Mat::zeros(pointCloud.size(), CV_32F));
88
 
89
 
89
    // merge channels
90
    // merge channels
90
    cv::Mat pointCloudPadded;
91
    cv::Mat pointCloudPadded;
91
    cv::merge(pointCloudChannels, pointCloudPadded);
92
    cv::merge(pointCloudChannels, pointCloudPadded);
92
 
93
 
93
    // memcpy everything
94
    // memcpy everything
94
    memcpy(&pointCloudPCL->points[0], pointCloudPadded.data, pointCloudPadded.rows*pointCloudPadded.cols*sizeof(pcl::PointXYZRGB));
95
    memcpy(&pointCloudPCL->points[0], pointCloudPadded.data, pointCloudPadded.rows*pointCloudPadded.cols*sizeof(pcl::PointXYZRGB));
95
 
96
 
96
//    // filtering
97
//    // filtering
97
//    pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> filter;
98
//    pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> filter;
98
//    filter.setMeanK(5);
99
//    filter.setMeanK(5);
99
//    filter.setStddevMulThresh(1.0);
100
//    filter.setStddevMulThresh(1.0);
100
//    filter.setInputCloud(pointCloudPCL);
101
//    filter.setInputCloud(pointCloudPCL);
101
//    pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloudFiltered(new pcl::PointCloud<pcl::PointXYZRGB>);
102
//    pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloudFiltered(new pcl::PointCloud<pcl::PointXYZRGB>);
102
//    filter.filter(*pointCloudFiltered);
103
//    filter.filter(*pointCloudFiltered);
103
 
104
 
104
    // Emit result
105
    // Emit result
105
    emit newPointCloud(pointCloudPCL);
106
    emit newPointCloud(pointCloudPCL);
106
 
107
 
107
    std::cout << "SMTriangulator: " << time.elapsed() << "ms" << std::endl;
108
    std::cout << "SMTriangulator: " << time.elapsed() << "ms" << std::endl;
108
 
109
 
109
    if(writeToDisk){
-
 
110
        QString fileName = QDateTime::currentDateTime().toString("yyyyMMdd_HHmmsszzz");
-
 
111
        fileName.append(".pcd");
-
 
112
        pcl::io::savePCDFileBinary(fileName.toStdString(), *pointCloudPCL);
-
 
113
    }
-
 
114
 
-
 
115
    //emit finished();
110
    //emit finished();
116
}
111
}
117
 
112
 
118
 
-
 
119
SMTriangulator::SMTriangulator(SMCalibrationParams _calibration, unsigned int frameWidth, unsigned int frameHeight) : calibration(_calibration){
-
 
120
 
-
 
121
    // Precompute uc, vc maps
-
 
122
    uc.create(frameHeight, frameWidth, CV_32F);
-
 
123
    vc.create(frameHeight, frameWidth, CV_32F);
-
 
124
 
-
 
125
    for(unsigned int row=0; row<frameHeight; row++){
-
 
126
        for(unsigned int col=0; col<frameWidth; col++){
-
 
127
            uc.at<float>(row, col) = col;
-
 
128
            vc.at<float>(row, col) = row;
-
 
129
        }
-
 
130
    }
-
 
131
 
-
 
132
    // Precompute determinant tensor
-
 
133
    cv::Mat Pc(3,4,CV_32F,cv::Scalar(0.0));
-
 
134
    cv::Mat(calibration.Kc).copyTo(Pc(cv::Range(0,3), cv::Range(0,3)));
-
 
135
 
-
 
136
    cv::Mat Pp(3,4,CV_32F), temp(3,4,CV_32F);
-
 
137
    cv::Mat(calibration.Rp).copyTo(temp(cv::Range(0,3), cv::Range(0,3)));
-
 
138
    cv::Mat(calibration.Tp).copyTo(temp(cv::Range(0,3), cv::Range(3,4)));
-
 
139
    Pp = cv::Mat(calibration.Kp) * temp;
-
 
140
 
-
 
141
    cv::Mat e = cv::Mat::eye(4, 4, CV_32F);
-
 
142
 
-
 
143
    int sz[] = {4, 3, 3, 3};
-
 
144
    cv::Mat C(4, sz, CV_32F, cv::Scalar::all(0));
-
 
145
    for(int k=0; k<4; k++){
-
 
146
        for(int i=0; i<3; i++){
-
 
147
            for(int j=0; j<3; j++){
-
 
148
                for(int l=0; l<3; l++){
-
 
149
                    cv::Mat op(4, 4, CV_32F);
-
 
150
                    Pc.row(i).copyTo(op.row(0));
-
 
151
                    Pc.row(j).copyTo(op.row(1));
-
 
152
                    Pp.row(l).copyTo(op.row(2));
-
 
153
                    e.row(k).copyTo(op.row(3));
-
 
154
                    C.at<float>(cv::Vec4i(k,i,j,l)) = cv::determinant(op.t());
-
 
155
                }
-
 
156
            }
-
 
157
        }
-
 
158
    }
-
 
159
    determinantTensor = C;
-
 
160
 
-
 
161
    // Precompute lens correction maps
-
 
162
    cv::Mat eye = cv::Mat::eye(3, 3, CV_32F);
-
 
163
    cv::initUndistortRectifyMap(calibration.Kc, calibration.kc, eye, calibration.Kc, cv::Size(frameWidth, frameHeight), CV_32FC1, lensMap1, lensMap2);
-
 
164
 
-
 
165
    //cv::Mat map1, map2;
-
 
166
    //cv::normalize(lensMap1, map1, 0, 255, cv::NORM_MINMAX, CV_8U);
-
 
167
    //cv::normalize(lensMap2, map2, 0, 255, cv::NORM_MINMAX, CV_8U);
-
 
168
    //cv::imwrite("map1.png", map1);
-
 
169
    //cv::imwrite("map2.png", map2);
-
 
170
}
-
 
171
 
-
 
172
void SMTriangulator::triangulate(cv::Mat &up, cv::Mat &vp, cv::Mat &mask, cv::Mat &shading, cv::Mat &pointCloud){
113
void SMTriangulator::triangulate(cv::Mat &up, cv::Mat &vp, cv::Mat &mask, cv::Mat &shading, cv::Mat &pointCloud){
173
 
114
 
174
    // Undistort up, mask and shading
115
    // Undistort up, mask and shading
175
    if(!up.empty()){
116
    if(!up.empty()){
176
        cv::Mat upUndistort;
117
        cv::Mat upUndistort;
177
        cv::remap(up, upUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
118
        cv::remap(up, upUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
178
        up = upUndistort;
119
        up = upUndistort;
179
    }
120
    }
180
    if(!vp.empty()){
121
    if(!vp.empty()){
181
        cv::Mat vpUndistort;
122
        cv::Mat vpUndistort;
182
        cv::remap(vp, vpUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
123
        cv::remap(vp, vpUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
183
        vp = vpUndistort;
124
        vp = vpUndistort;
184
    }
125
    }
185
 
126
 
186
    cv::Mat maskUndistort, shadingUndistort;
127
    cv::Mat maskUndistort, shadingUndistort;
187
    cv::remap(mask, maskUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
128
    cv::remap(mask, maskUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
188
    cv::remap(shading, shadingUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
129
    cv::remap(shading, shadingUndistort, lensMap1, lensMap2, cv::INTER_LINEAR);
189
    mask = maskUndistort;
130
    mask = maskUndistort;
190
    shading = shadingUndistort;
131
    shading = shadingUndistort;
191
 
132
 
192
    // Triangulate
133
    // Triangulate
193
    cv::Mat xyz;
134
    cv::Mat xyz;
194
    if(!up.empty() && vp.empty())
135
    if(!up.empty() && vp.empty())
195
        triangulateFromUp(up, xyz);
136
        triangulateFromUp(up, xyz);
196
    else if(!vp.empty() && up.empty())
137
    else if(!vp.empty() && up.empty())
197
        triangulateFromVp(vp, xyz);
138
        triangulateFromVp(vp, xyz);
198
    else if(!up.empty() && !vp.empty())
139
    else if(!up.empty() && !vp.empty())
199
        triangulateFromUpVp(up, vp, xyz);
140
        triangulateFromUpVp(up, vp, xyz);
200
 
141
 
201
    // Merge and mask
142
    // Merge and mask
202
    pointCloud = cv::Mat(up.size(), CV_32FC3, cv::Scalar(NAN, NAN, NAN));
143
    pointCloud = cv::Mat(up.size(), CV_32FC3, cv::Scalar(NAN, NAN, NAN));
203
    xyz.copyTo(pointCloud, mask);
144
    xyz.copyTo(pointCloud, mask);
204
 
145
 
205
}
146
}
206
 
147
 
207
void SMTriangulator::triangulateFromUp(cv::Mat &up, cv::Mat &xyz){
148
void SMTriangulator::triangulateFromUp(cv::Mat &up, cv::Mat &xyz){
208
 
149
 
209
    // Solve for xyzw using determinant tensor
150
    // Solve for xyzw using determinant tensor
210
    cv::Mat C = determinantTensor;
151
    cv::Mat C = determinantTensor;
211
    std::vector<cv::Mat> xyzw(4);
152
    std::vector<cv::Mat> xyzw(4);
212
    for(unsigned int i=0; i<4; i++){
153
    for(unsigned int i=0; i<4; i++){
213
        xyzw[i].create(up.size(), CV_32F);
154
        xyzw[i].create(up.size(), CV_32F);
214
        xyzw[i] = C.at<float>(cv::Vec4i(i,0,1,0)) - C.at<float>(cv::Vec4i(i,2,1,0))*uc - C.at<float>(cv::Vec4i(i,0,2,0))*vc -
155
        xyzw[i] = C.at<float>(cv::Vec4i(i,0,1,0)) - C.at<float>(cv::Vec4i(i,2,1,0))*uc - C.at<float>(cv::Vec4i(i,0,2,0))*vc -
215
                C.at<float>(cv::Vec4i(i,0,1,2))*up + C.at<float>(cv::Vec4i(i,2,1,2))*up.mul(uc) + C.at<float>(cv::Vec4i(i,0,2,2))*up.mul(vc);
156
                C.at<float>(cv::Vec4i(i,0,1,2))*up + C.at<float>(cv::Vec4i(i,2,1,2))*up.mul(uc) + C.at<float>(cv::Vec4i(i,0,2,2))*up.mul(vc);
216
    }
157
    }
217
 
158
 
218
    // Convert to non homogenous coordinates
159
    // Convert to non homogenous coordinates
219
    for(unsigned int i=0; i<3; i++)
160
    for(unsigned int i=0; i<3; i++)
220
        xyzw[i] /= xyzw[3];
161
        xyzw[i] /= xyzw[3];
221
 
162
 
222
    // Merge and mask
163
    // Merge and mask
223
    cv::merge(std::vector<cv::Mat>(xyzw.begin(), xyzw.begin()+3), xyz);
164
    cv::merge(std::vector<cv::Mat>(xyzw.begin(), xyzw.begin()+3), xyz);
224
 
165
 
225
}
166
}
226
 
167
 
227
void SMTriangulator::triangulateFromVp(cv::Mat &vp, cv::Mat &xyz){
168
void SMTriangulator::triangulateFromVp(cv::Mat &vp, cv::Mat &xyz){
228
 
169
 
229
    // Solve for xyzw using determinant tensor
170
    // Solve for xyzw using determinant tensor
230
    cv::Mat C = determinantTensor;
171
    cv::Mat C = determinantTensor;
231
    std::vector<cv::Mat> xyzw(4);
172
    std::vector<cv::Mat> xyzw(4);
232
    for(unsigned int i=0; i<4; i++){
173
    for(unsigned int i=0; i<4; i++){
233
        xyzw[i].create(vp.size(), CV_32F);
174
        xyzw[i].create(vp.size(), CV_32F);
234
        xyzw[i] = C.at<float>(cv::Vec4i(i,0,1,1)) - C.at<float>(cv::Vec4i(i,2,1,1))*uc - C.at<float>(cv::Vec4i(i,0,2,1))*vc -
175
        xyzw[i] = C.at<float>(cv::Vec4i(i,0,1,1)) - C.at<float>(cv::Vec4i(i,2,1,1))*uc - C.at<float>(cv::Vec4i(i,0,2,1))*vc -
235
                C.at<float>(cv::Vec4i(i,0,1,2))*vp + C.at<float>(cv::Vec4i(i,2,1,2))*vp.mul(uc) + C.at<float>(cv::Vec4i(i,0,2,2))*vp.mul(vc);
176
                C.at<float>(cv::Vec4i(i,0,1,2))*vp + C.at<float>(cv::Vec4i(i,2,1,2))*vp.mul(uc) + C.at<float>(cv::Vec4i(i,0,2,2))*vp.mul(vc);
236
    }
177
    }
237
 
178
 
238
    // Convert to non homogenous coordinates
179
    // Convert to non homogenous coordinates
239
    for(unsigned int i=0; i<3; i++)
180
    for(unsigned int i=0; i<3; i++)
240
        xyzw[i] /= xyzw[3];
181
        xyzw[i] /= xyzw[3];
241
 
182
 
242
    // Merge and mask
183
    // Merge and mask
243
    cv::merge(std::vector<cv::Mat>(xyzw.begin(), xyzw.begin()+3), xyz);
184
    cv::merge(std::vector<cv::Mat>(xyzw.begin(), xyzw.begin()+3), xyz);
244
 
185
 
245
}
186
}
246
 
187
 
247
void SMTriangulator::triangulateFromUpVp(cv::Mat &up, cv::Mat &vp, cv::Mat &xyz){
188
void SMTriangulator::triangulateFromUpVp(cv::Mat &up, cv::Mat &vp, cv::Mat &xyz){
248
 
189
 
249
    std::cerr << "WARNING! NOT FULLY IMPLEMENTED!" << std::endl;
190
//    std::cerr << "WARNING! NOT FULLY IMPLEMENTED!" << std::endl;
250
    int N = up.rows * up.cols;
191
//    int N = up.rows * up.cols;
251
 
192
 
252
    cv::Mat projPointsCam(2, N, CV_32F);
193
//    cv::Mat projPointsCam(2, N, CV_32F);
253
    uc.reshape(0,1).copyTo(projPointsCam.row(0));
194
//    uc.reshape(0,1).copyTo(projPointsCam.row(0));
254
    vc.reshape(0,1).copyTo(projPointsCam.row(1));
195
//    vc.reshape(0,1).copyTo(projPointsCam.row(1));
255
 
196
 
256
    cv::Mat projPointsProj(2, N, CV_32F);
197
//    cv::Mat projPointsProj(2, N, CV_32F);
257
    up.reshape(0,1).copyTo(projPointsProj.row(0));
198
//    up.reshape(0,1).copyTo(projPointsProj.row(0));
258
    vp.reshape(0,1).copyTo(projPointsProj.row(1));
199
//    vp.reshape(0,1).copyTo(projPointsProj.row(1));
259
 
200
 
260
    cv::Mat Pc(3,4,CV_32F,cv::Scalar(0.0));
201
//    cv::Mat Pc(3,4,CV_32F,cv::Scalar(0.0));
261
    cv::Mat(calibration.Kc).copyTo(Pc(cv::Range(0,3), cv::Range(0,3)));
202
//    cv::Mat(calibration.Kc).copyTo(Pc(cv::Range(0,3), cv::Range(0,3)));
262
 
203
 
263
    cv::Mat Pp(3,4,CV_32F), temp(3,4,CV_32F);
204
//    cv::Mat Pp(3,4,CV_32F), temp(3,4,CV_32F);
264
    cv::Mat(calibration.Rp).copyTo(temp(cv::Range(0,3), cv::Range(0,3)));
205
//    cv::Mat(calibration.Rp).copyTo(temp(cv::Range(0,3), cv::Range(0,3)));
265
    cv::Mat(calibration.Tp).copyTo(temp(cv::Range(0,3), cv::Range(3,4)));
206
//    cv::Mat(calibration.Tp).copyTo(temp(cv::Range(0,3), cv::Range(3,4)));
266
    Pp = cv::Mat(calibration.Kp) * temp;
207
//    Pp = cv::Mat(calibration.Kp) * temp;
267
 
208
 
268
    cv::Mat xyzw;
209
//    cv::Mat xyzw;
269
    cv::triangulatePoints(Pc, Pp, projPointsCam, projPointsProj, xyzw);
210
//    cv::triangulatePoints(Pc, Pp, projPointsCam, projPointsProj, xyzw);
270
 
211
 
271
    xyz.create(3, N, CV_32F);
212
//    xyz.create(3, N, CV_32F);
272
    for(int i=0; i<N; i++){
213
//    for(int i=0; i<N; i++){
273
        xyz.at<float>(0,i) = xyzw.at<float>(0,i)/xyzw.at<float>(3,i);
214
//        xyz.at<float>(0,i) = xyzw.at<float>(0,i)/xyzw.at<float>(3,i);
274
        xyz.at<float>(1,i) = xyzw.at<float>(1,i)/xyzw.at<float>(3,i);
215
//        xyz.at<float>(1,i) = xyzw.at<float>(1,i)/xyzw.at<float>(3,i);
275
        xyz.at<float>(2,i) = xyzw.at<float>(2,i)/xyzw.at<float>(3,i);
216
//        xyz.at<float>(2,i) = xyzw.at<float>(2,i)/xyzw.at<float>(3,i);
276
    }
217
//    }
277
 
218
 
278
    xyz = xyz.t();
219
//    xyz = xyz.t();
279
    xyz = xyz.reshape(3, up.rows);
220
//    xyz = xyz.reshape(3, up.rows);
280
}
221
}
281
 
222
 
282
SMSMTriangulator::~SMSMTriangulator(){
223
SMTriangulator::~SMTriangulator(){
283
    delete calibration;
-
 
284
    delete SMTriangulator;
-
 
285
 
224
 
286
    std::cout<<"SMTriangulatorWorker deleted\n"<<std::flush;
225
    std::cout << "SMTriangulator deleted.\n" << std::flush;
287
}
226
}
288
 
227
 
289
 
228