Line 86... |
Line 86... |
86 |
void AlgorithmGrayCode::get3DPoints(const SMCalibrationParameters &calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
|
86 |
void AlgorithmGrayCode::get3DPoints(const SMCalibrationParameters &calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
|
87 |
|
87 |
|
88 |
assert(frames0.size() == N);
|
88 |
assert(frames0.size() == N);
|
89 |
assert(frames1.size() == N);
|
89 |
assert(frames1.size() == N);
|
90 |
|
90 |
|
91 |
// for(int i=0; i<1920; i++){
|
- |
|
92 |
// std::cout << i << " " << binaryToGray(i) << " " << grayToBinary(binaryToGray(i)) << std::endl;
|
- |
|
93 |
// }
|
- |
|
94 |
|
- |
|
95 |
int frameRows = frames0[0].rows;
|
91 |
int frameRows = frames0[0].rows;
|
96 |
int frameCols = frames0[0].cols;
|
92 |
int frameCols = frames0[0].cols;
|
97 |
|
93 |
|
98 |
// rectifying homographies (rotation+projections)
|
94 |
// rectifying homographies (rotation+projections)
|
99 |
cv::Size frameSize(frameCols, frameRows);
|
95 |
cv::Size frameSize(frameCols, frameRows);
|
Line 102... |
Line 98... |
102 |
cv::Mat(calibration.R1).convertTo(R, CV_64F);
|
98 |
cv::Mat(calibration.R1).convertTo(R, CV_64F);
|
103 |
cv::Mat(calibration.T1).convertTo(T, CV_64F);
|
99 |
cv::Mat(calibration.T1).convertTo(T, CV_64F);
|
104 |
cv::Mat R0, R1, P0, P1, QRect;
|
100 |
cv::Mat R0, R1, P0, P1, QRect;
|
105 |
cv::stereoRectify(calibration.K0, calibration.k0, calibration.K1, calibration.k1, frameSize, R, T, R0, R1, P0, P1, QRect, 0);
|
101 |
cv::stereoRectify(calibration.K0, calibration.k0, calibration.K1, calibration.k1, frameSize, R, T, R0, R1, P0, P1, QRect, 0);
|
106 |
|
102 |
|
107 |
// std::cout << "R0" << std::endl << R0 << std::endl;
|
- |
|
108 |
// std::cout << "P0" << std::endl << P0 << std::endl;
|
- |
|
109 |
// std::cout << "R1" << std::endl << R1 << std::endl;
|
- |
|
110 |
// std::cout << "P1" << std::endl << P1 << std::endl;
|
- |
|
111 |
|
- |
|
112 |
// interpolation maps
|
103 |
// interpolation maps
|
113 |
cv::Mat map0X, map0Y, map1X, map1Y;
|
104 |
cv::Mat map0X, map0Y, map1X, map1Y;
|
114 |
cv::initUndistortRectifyMap(calibration.K0, calibration.k0, R0, P0, frameSize, CV_32F, map0X, map0Y);
|
105 |
cv::initUndistortRectifyMap(calibration.K0, calibration.k0, R0, P0, frameSize, CV_32F, map0X, map0Y);
|
115 |
cv::initUndistortRectifyMap(calibration.K1, calibration.k1, R1, P1, frameSize, CV_32F, map1X, map1Y);
|
106 |
cv::initUndistortRectifyMap(calibration.K1, calibration.k1, R1, P1, frameSize, CV_32F, map1X, map1Y);
|
116 |
|
107 |
|
Line 123... |
Line 114... |
123 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
|
114 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
|
124 |
cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
|
115 |
cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
|
125 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
|
116 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
|
126 |
}
|
117 |
}
|
127 |
|
118 |
|
128 |
|
- |
|
- |
|
119 |
#ifdef SM_DEBUG
|
129 |
// cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
120 |
cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
130 |
// cvtools::writeMat(frames0[0], "frames0_0.mat", "frames0_0");
|
121 |
cvtools::writeMat(frames0[0], "frames0_0.mat", "frames0_0");
|
131 |
|
122 |
|
132 |
// cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
123 |
cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
133 |
// cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
124 |
cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
134 |
|
125 |
|
135 |
// cv::imwrite("frames0[0].png", frames0[0]);
|
126 |
cv::imwrite("frames0[0].png", frames0[0]);
|
136 |
// cv::imwrite("frames0Rect[0].png", frames0Rect[0]);
|
127 |
cv::imwrite("frames0Rect[0].png", frames0Rect[0]);
|
137 |
|
128 |
|
138 |
// cv::imwrite("frames1[0].png", frames1[0]);
|
129 |
cv::imwrite("frames1[0].png", frames1[0]);
|
139 |
// cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
|
130 |
cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
|
- |
|
131 |
#endif
|
140 |
|
132 |
|
141 |
// color debayer and remap
|
133 |
// color debayer and remap
|
142 |
cv::Mat color0Rect, color1Rect;
|
134 |
cv::Mat color0Rect, color1Rect;
|
143 |
// frames0[0].convertTo(color0Rect, CV_8UC1, 1.0/256.0);
|
- |
|
144 |
cv::cvtColor(frames0[0], color0Rect, CV_BayerBG2RGB);
|
135 |
cv::cvtColor(frames0[0], color0Rect, CV_BayerBG2RGB);
|
145 |
cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
|
136 |
cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
|
146 |
|
137 |
|
147 |
// frames1[0].convertTo(color1Rect, CV_8UC1, 1.0/256.0);
|
- |
|
148 |
cv::cvtColor(frames1[0], color1Rect, CV_BayerBG2RGB);
|
138 |
cv::cvtColor(frames1[0], color1Rect, CV_BayerBG2RGB);
|
149 |
cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
|
139 |
cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
|
150 |
|
140 |
|
151 |
int frameRectRows = frames0Rect[0].rows;
|
141 |
int frameRectRows = frames0Rect[0].rows;
|
152 |
int frameRectCols = frames0Rect[0].cols;
|
142 |
int frameRectCols = frames0Rect[0].cols;
|
153 |
|
143 |
|
154 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
- |
|
155 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
- |
|
156 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
157 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
158 |
|
- |
|
159 |
// occlusion masks
|
144 |
// occlusion masks
|
160 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
145 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
161 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
146 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
162 |
occlusion0Rect = (occlusion0Rect > 10) & (occlusion0Rect < 250);
|
147 |
occlusion0Rect = (occlusion0Rect > 10) & (occlusion0Rect < 250);
|
163 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
148 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
Line 166... |
Line 151... |
166 |
// erode occlusion masks
|
151 |
// erode occlusion masks
|
167 |
cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
|
152 |
cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
|
168 |
cv::erode(occlusion0Rect, occlusion0Rect, strel);
|
153 |
cv::erode(occlusion0Rect, occlusion0Rect, strel);
|
169 |
cv::erode(occlusion1Rect, occlusion1Rect, strel);
|
154 |
cv::erode(occlusion1Rect, occlusion1Rect, strel);
|
170 |
|
155 |
|
171 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
- |
|
172 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
- |
|
173 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
174 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
175 |
|
- |
|
176 |
// // correct for projector inversion error
|
156 |
// // correct for projector inversion error
|
177 |
// cv::Mat W;
|
157 |
// cv::Mat W;
|
178 |
// cv::add(frames0Rect[0], frames0Rect[1], W, cv::noArray(), CV_32F);
|
158 |
// cv::add(frames0Rect[0], frames0Rect[1], W, cv::noArray(), CV_32F);
|
179 |
// for(int i=2; i<N; i+=2){
|
159 |
// for(int i=2; i<N; i+=2){
|
180 |
// cv::Mat S, E;
|
160 |
// cv::Mat S, E;
|
Line 183... |
Line 163... |
183 |
// E *= 0.5;
|
163 |
// E *= 0.5;
|
184 |
// cv::add(frames0Rect[i], E, frames0Rect[i], cv::noArray(), CV_16UC1);
|
164 |
// cv::add(frames0Rect[i], E, frames0Rect[i], cv::noArray(), CV_16UC1);
|
185 |
// cv::add(frames0Rect[i+1], E, frames0Rect[i+1], cv::noArray(), CV_16UC1);
|
165 |
// cv::add(frames0Rect[i+1], E, frames0Rect[i+1], cv::noArray(), CV_16UC1);
|
186 |
// }
|
166 |
// }
|
187 |
|
167 |
|
188 |
|
- |
|
189 |
// // correct for texture modulation and ambient
|
168 |
// // correct for texture modulation and ambient
|
190 |
// cv::Mat A0 = frames0Rect[1];
|
169 |
// cv::Mat A0 = frames0Rect[1];
|
191 |
// cv::Mat M0 = frames0Rect[0]-frames0Rect[1];
|
170 |
// cv::Mat M0 = frames0Rect[0]-frames0Rect[1];
|
192 |
////cvtools::writeMat(A0, "A0.mat", "A0");
|
- |
|
193 |
////cvtools::writeMat(M0, "M0.mat", "M0");
|
- |
|
194 |
////cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
195 |
////cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
196 |
// cv::divide(256.0, M0, M0, CV_32F);
|
171 |
// cv::divide(256.0, M0, M0, CV_32F);
|
197 |
// cv::Mat A1 = frames1Rect[1];
|
172 |
// cv::Mat A1 = frames1Rect[1];
|
198 |
// cv::Mat M1 = frames1Rect[0]-frames1Rect[1];
|
173 |
// cv::Mat M1 = frames1Rect[0]-frames1Rect[1];
|
199 |
// cv::divide(256.0, M1, M1, CV_32F);
|
174 |
// cv::divide(256.0, M1, M1, CV_32F);
|
200 |
|
175 |
|
201 |
// for(int i=2; i<N; i++){
|
176 |
// for(int i=2; i<N; i++){
|
202 |
// cv::multiply(frames0Rect[i]-A0, M0, frames0Rect[i], 1.0, CV_8UC1);
|
177 |
// cv::multiply(frames0Rect[i]-A0, M0, frames0Rect[i], 1.0, CV_8UC1);
|
203 |
// cv::multiply(frames1Rect[i]-A1, M1, frames1Rect[i], 1.0, CV_8UC1);
|
178 |
// cv::multiply(frames1Rect[i]-A1, M1, frames1Rect[i], 1.0, CV_8UC1);
|
204 |
// }
|
179 |
// }
|
205 |
|
180 |
|
206 |
//cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
- |
|
207 |
//cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
- |
|
208 |
|
- |
|
209 |
//cvtools::writeMat(occlusion0Rect, "occlusion0Rect.mat", "occlusion0Rect");
|
- |
|
210 |
//cvtools::writeMat(occlusion1Rect, "occlusion1Rect.mat", "occlusion1Rect");
|
- |
|
211 |
|
- |
|
212 |
// decode patterns
|
181 |
// decode patterns
|
213 |
cv::Mat code0Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
182 |
cv::Mat code0Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
214 |
cv::Mat code1Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
183 |
cv::Mat code1Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
215 |
|
184 |
|
216 |
// into gray code
|
185 |
// into gray code
|
Line 228... |
Line 197... |
228 |
|
197 |
|
229 |
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
198 |
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
230 |
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
199 |
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
231 |
|
200 |
|
232 |
|
201 |
|
- |
|
202 |
#ifdef SM_DEBUG
|
233 |
// // convert to standard binary
|
203 |
// convert to standard binary
|
234 |
// cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
|
204 |
cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
|
235 |
// cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
|
205 |
cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
|
236 |
// for(int r=0; r<frameRectRows; r++){
|
206 |
for(int r=0; r<frameRectRows; r++){
|
237 |
// for(int c=0; c<frameRectCols; c++){
|
207 |
for(int c=0; c<frameRectCols; c++){
|
238 |
// if(code0Rect.at<int>(r,c) != -1)
|
208 |
if(code0Rect.at<int>(r,c) != -1)
|
239 |
// code0Binary.at<float>(r,c) = grayToBinary(code0Rect.at<int>(r,c));
|
209 |
code0Binary.at<float>(r,c) = grayToBinary(code0Rect.at<int>(r,c));
|
240 |
// if(code1Rect.at<int>(r,c) != -1)
|
210 |
if(code1Rect.at<int>(r,c) != -1)
|
241 |
// code1Binary.at<float>(r,c) = grayToBinary(code1Rect.at<int>(r,c));
|
211 |
code1Binary.at<float>(r,c) = grayToBinary(code1Rect.at<int>(r,c));
|
242 |
// }
|
212 |
}
|
243 |
// }
|
213 |
}
|
244 |
|
214 |
|
245 |
//cvtools::writeMat(code0Binary, "code0Binary.mat", "code0Binary");
|
215 |
cvtools::writeMat(code0Binary, "code0Binary.mat", "code0Binary");
|
246 |
//cvtools::writeMat(code1Binary, "code1Binary.mat", "code1Binary");
|
216 |
cvtools::writeMat(code1Binary, "code1Binary.mat", "code1Binary");
|
- |
|
217 |
#endif
|
247 |
|
218 |
|
248 |
// // threshold on vertical discontinuities (due to imperfect rectification)
|
219 |
// // threshold on vertical discontinuities (due to imperfect rectification)
|
249 |
// cv::Mat edges0;
|
220 |
// cv::Mat edges0;
|
250 |
// cv::Sobel(code0Binary, edges0, -1, 0, 1, 5);
|
221 |
// cv::Sobel(code0Binary, edges0, -1, 0, 1, 5);
|
251 |
// occlusion0Rect = occlusion0Rect & (abs(edges0) < 50);
|
222 |
// occlusion0Rect = occlusion0Rect & (abs(edges0) < 50);
|
252 |
|
223 |
|
253 |
// cv::Mat edges1;
|
224 |
// cv::Mat edges1;
|
254 |
// cv::Sobel(code1Binary, edges1, -1, 0, 1, 5);
|
225 |
// cv::Sobel(code1Binary, edges1, -1, 0, 1, 5);
|
255 |
// occlusion1Rect = occlusion1Rect & (abs(edges1) < 50);
|
226 |
// occlusion1Rect = occlusion1Rect & (abs(edges1) < 50);
|
256 |
|
227 |
|
257 |
//cvtools::writeMat(edges0, "edges0.mat", "edges0");
|
- |
|
258 |
//cvtools::writeMat(edges1, "edges1.mat", "edges1");
|
- |
|
259 |
|
228 |
|
260 |
// set occluded pixels to -1
|
229 |
// set occluded pixels to -1
|
261 |
for(int r=0; r<frameRectRows; r++){
|
230 |
for(int r=0; r<frameRectRows; r++){
|
262 |
for(int c=0; c<frameRectCols; c++){
|
231 |
for(int c=0; c<frameRectCols; c++){
|
263 |
if(occlusion0Rect.at<unsigned char>(r,c) == 0)
|
232 |
if(occlusion0Rect.at<unsigned char>(r,c) == 0)
|
Line 265... |
Line 234... |
265 |
if(occlusion1Rect.at<unsigned char>(r,c) == 0)
|
234 |
if(occlusion1Rect.at<unsigned char>(r,c) == 0)
|
266 |
code1Rect.at<int>(r,c) = -1;
|
235 |
code1Rect.at<int>(r,c) = -1;
|
267 |
}
|
236 |
}
|
268 |
}
|
237 |
}
|
269 |
|
238 |
|
- |
|
239 |
#ifdef SM_DEBUG
|
270 |
// cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
240 |
cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
271 |
// cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
241 |
cvtools::writeMat*/(code1Rect, "code1Rect.mat", "code1Rect");
|
- |
|
242 |
#endif
|
272 |
|
243 |
|
273 |
// matching
|
244 |
// matching
|
274 |
std::vector<cv::Vec2f> q0Rect, q1Rect;
|
245 |
std::vector<cv::Vec2f> q0, q1;
|
275 |
for(int row=0; row<frameRectRows; row++){
|
246 |
for(int row=0; row<frameRectRows; row++){
|
276 |
|
247 |
|
277 |
// edge data structure containing [floor(column), labelLeft, labelRight, orderingRelation]
|
248 |
// edge data structure containing [floor(column), labelLeft, labelRight, orderingRelation]
|
278 |
std::vector<cv::Vec4i> edges0, edges1;
|
249 |
std::vector<cv::Vec4i> edges0, edges1;
|
279 |
|
250 |
|
Line 312... |
Line 283... |
312 |
float pos1 = frames0Rect[2*level+2].at<unsigned char>(row, c1);
|
283 |
float pos1 = frames0Rect[2*level+2].at<unsigned char>(row, c1);
|
313 |
float neg0 = frames0Rect[2*level+3].at<unsigned char>(row, c0);
|
284 |
float neg0 = frames0Rect[2*level+3].at<unsigned char>(row, c0);
|
314 |
float neg1 = frames0Rect[2*level+3].at<unsigned char>(row, c1);
|
285 |
float neg1 = frames0Rect[2*level+3].at<unsigned char>(row, c1);
|
315 |
|
286 |
|
316 |
float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
287 |
float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
317 |
q0Rect.push_back(cv::Point2f(col, row));
|
288 |
q0.push_back(cv::Point2f(col, row));
|
318 |
|
289 |
|
319 |
// refine for camera 1
|
290 |
// refine for camera 1
|
320 |
c0 = matchedEdges1[i][0];
|
291 |
c0 = matchedEdges1[i][0];
|
321 |
c1 = c0+1;
|
292 |
c1 = c0+1;
|
322 |
|
293 |
|
Line 324... |
Line 295... |
324 |
pos1 = frames1Rect[2*level+2].at<unsigned char>(row, c1);
|
295 |
pos1 = frames1Rect[2*level+2].at<unsigned char>(row, c1);
|
325 |
neg0 = frames1Rect[2*level+3].at<unsigned char>(row, c0);
|
296 |
neg0 = frames1Rect[2*level+3].at<unsigned char>(row, c0);
|
326 |
neg1 = frames1Rect[2*level+3].at<unsigned char>(row, c1);
|
297 |
neg1 = frames1Rect[2*level+3].at<unsigned char>(row, c1);
|
327 |
|
298 |
|
328 |
col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
299 |
col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
329 |
q1Rect.push_back(cv::Point2f(col, row));
|
300 |
q1.push_back(cv::Point2f(col, row));
|
330 |
|
301 |
|
331 |
}
|
302 |
}
|
332 |
|
303 |
|
333 |
}
|
304 |
}
|
334 |
|
305 |
|
335 |
int nMatches = q0Rect.size();
|
306 |
int nMatches = q0.size();
|
336 |
|
307 |
|
337 |
if(nMatches < 1){
|
308 |
if(nMatches < 1){
|
338 |
Q.resize(0);
|
309 |
Q.resize(0);
|
339 |
color.resize(0);
|
310 |
color.resize(0);
|
340 |
|
311 |
|
Line 343... |
Line 314... |
343 |
|
314 |
|
344 |
// retrieve color information (at integer coordinates)
|
315 |
// retrieve color information (at integer coordinates)
|
345 |
color.resize(nMatches);
|
316 |
color.resize(nMatches);
|
346 |
for(int i=0; i<nMatches; i++){
|
317 |
for(int i=0; i<nMatches; i++){
|
347 |
|
318 |
|
348 |
cv::Vec3b c0 = color0Rect.at<cv::Vec3b>(q0Rect[i][1], q0Rect[i][0]);
|
319 |
cv::Vec3b c0 = color0Rect.at<cv::Vec3b>(q0[i][1], q0[i][0]);
|
349 |
cv::Vec3b c1 = color1Rect.at<cv::Vec3b>(q1Rect[i][1], q1Rect[i][0]);
|
320 |
cv::Vec3b c1 = color1Rect.at<cv::Vec3b>(q1[i][1], q1[i][0]);
|
350 |
|
321 |
|
351 |
color[i] = 0.5*c0 + 0.5*c1;
|
322 |
color[i] = 0.5*c0 + 0.5*c1;
|
352 |
}
|
323 |
}
|
353 |
|
324 |
|
354 |
// // Triangulate points
|
- |
|
355 |
// cv::Mat QMatHomogenous, QMat;
|
- |
|
356 |
//// cv::Mat C0 = P0.clone();
|
- |
|
357 |
//// cv::Mat C1 = P1.clone();
|
- |
|
358 |
//// C0.colRange(0, 3) = C0.colRange(0, 3)*R0;
|
- |
|
359 |
//// C1.colRange(0, 3) = C1.colRange(0, 3)*R1.t();
|
- |
|
360 |
// cv::triangulatePoints(P0, P1, q0Rect, q1Rect, QMatHomogenous);
|
- |
|
361 |
// cvtools::convertMatFromHomogeneous(QMatHomogenous, QMat);
|
- |
|
362 |
|
- |
|
363 |
// // undo rectifying rotation
|
- |
|
364 |
// cv::Mat R0Inv;
|
- |
|
365 |
// cv::Mat(R0.t()).convertTo(R0Inv, CV_32F);
|
- |
|
366 |
// QMat = R0Inv*QMat;
|
- |
|
367 |
|
- |
|
368 |
// cvtools::matToPoints3f(QMat, Q);
|
- |
|
369 |
|
- |
|
370 |
|
- |
|
371 |
// Triangulate by means of disparity projection
|
325 |
// Triangulate by means of disparity projection
|
372 |
Q.resize(q0Rect.size());
|
326 |
Q.resize(q0.size());
|
373 |
cv::Matx44f QRectx = cv::Matx44f(QRect);
|
327 |
cv::Matx44f QRectx = cv::Matx44f(QRect);
|
374 |
cv::Matx33f R0invx = cv::Matx33f(cv::Mat(R0.t()));
|
328 |
cv::Matx33f R0invx = cv::Matx33f(cv::Mat(R0.t()));
|
375 |
|
329 |
|
376 |
#pragma omp parallel for
|
330 |
#pragma omp parallel for
|
377 |
for(unsigned int i=0; i<q0Rect.size(); i++){
|
331 |
for(unsigned int i=0; i<q0.size(); i++){
|
378 |
float disparity = q0Rect[i][0]-q1Rect[i][0];
|
332 |
float disparity = q0[i][0]-q1[i][0];
|
379 |
cv::Vec4f Qih = QRectx*cv::Vec4f(q0Rect[i][0], q0Rect[i][1], disparity, 1.0);
|
333 |
cv::Vec4f Qih = QRectx*cv::Vec4f(q0[i][0], q0[i][1], disparity, 1.0);
|
380 |
float winv = float(1.0)/Qih[3];
|
334 |
float winv = float(1.0)/Qih[3];
|
381 |
Q[i] = R0invx * cv::Point3f(Qih[0]*winv, Qih[1]*winv, Qih[2]*winv);
|
335 |
Q[i] = R0invx * cv::Point3f(Qih[0]*winv, Qih[1]*winv, Qih[2]*winv);
|
382 |
}
|
336 |
}
|
383 |
|
337 |
|
384 |
}
|
338 |
}
|