Line 131... |
Line 131... |
131 |
|
131 |
|
132 |
}
|
132 |
}
|
133 |
|
133 |
|
134 |
}
|
134 |
}
|
135 |
|
135 |
|
136 |
void AlgorithmLineShift::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){
|
136 |
void AlgorithmLineShift::get3DPoints(const SMCalibrationParameters & calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3f>& color){
|
137 |
|
137 |
|
138 |
assert(frames0.size() == N);
|
138 |
assert(frames0.size() == N);
|
139 |
assert(frames1.size() == N);
|
139 |
assert(frames1.size() == N);
|
140 |
|
140 |
|
141 |
int frameRows = frames0[0].rows;
|
141 |
int frameRows = frames0[0].rows;
|
Line 158... |
Line 158... |
158 |
// gray-scale and remap
|
158 |
// gray-scale and remap
|
159 |
std::vector<cv::Mat> frames0Rect(N);
|
159 |
std::vector<cv::Mat> frames0Rect(N);
|
160 |
std::vector<cv::Mat> frames1Rect(N);
|
160 |
std::vector<cv::Mat> frames1Rect(N);
|
161 |
for(unsigned int i=0; i<N; i++){
|
161 |
for(unsigned int i=0; i<N; i++){
|
162 |
cv::Mat temp;
|
162 |
cv::Mat temp;
|
163 |
cv::cvtColor(frames0[i], temp, CV_BayerBG2GRAY);
|
163 |
cv::cvtColor(frames0[i], temp, CV_RGB2GRAY);
|
164 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_CUBIC);
|
164 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_CUBIC);
|
165 |
cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
|
165 |
cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
|
166 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_CUBIC);
|
166 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_CUBIC);
|
167 |
}
|
167 |
}
|
168 |
|
168 |
|
169 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
169 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
170 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
170 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
171 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
171 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
172 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
172 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
173 |
|
173 |
|
174 |
// color debayer and remap
|
174 |
// color debayer and remap
|
175 |
cv::Mat color0Rect, color1Rect;
|
175 |
cv::Mat color0Rect, color1Rect;
|
176 |
cv::cvtColor(frames0[0], color0Rect, CV_BayerBG2RGB);
|
- |
|
177 |
cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_CUBIC);
|
176 |
cv::remap(frames0[0], color0Rect, map0X, map0Y, CV_INTER_CUBIC);
|
178 |
|
- |
|
179 |
cv::cvtColor(frames1[0], color1Rect, CV_BayerBG2RGB);
|
- |
|
180 |
cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_CUBIC);
|
177 |
cv::remap(frames1[0], color1Rect, map1X, map1Y, CV_INTER_CUBIC);
|
181 |
|
178 |
|
182 |
int frameRectRows = frames0Rect[0].rows;
|
179 |
int frameRectRows = frames0Rect[0].rows;
|
183 |
int frameRectCols = frames0Rect[0].cols;
|
180 |
int frameRectCols = frames0Rect[0].cols;
|
184 |
|
181 |
|
185 |
// occlusion masks
|
182 |
// occlusion masks
|
186 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
183 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
187 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
184 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
188 |
occlusion0Rect = (occlusion0Rect > 20) & (occlusion0Rect < 250);
|
185 |
occlusion0Rect = (occlusion0Rect > 0.1) & (occlusion0Rect < 0.98);
|
189 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
186 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
190 |
occlusion1Rect = (occlusion1Rect > 20) & (occlusion1Rect < 250);
|
187 |
occlusion1Rect = (occlusion1Rect > 0.1) & (occlusion1Rect < 0.98);
|
191 |
|
188 |
|
192 |
// cvtools::writeMat(occlusion0Rect, "occlusion0Rect.mat", "occlusion0Rect");
|
189 |
// cvtools::writeMat(occlusion0Rect, "occlusion0Rect.mat", "occlusion0Rect");
|
193 |
// cvtools::writeMat(occlusion1Rect, "occlusion1Rect.mat", "occlusion1Rect");
|
190 |
// cvtools::writeMat(occlusion1Rect, "occlusion1Rect.mat", "occlusion1Rect");
|
194 |
|
191 |
|
195 |
// erode occlusion masks
|
192 |
// erode occlusion masks
|
Line 318... |
Line 315... |
318 |
|
315 |
|
319 |
// retrieve color information (at integer coordinates)
|
316 |
// retrieve color information (at integer coordinates)
|
320 |
color.resize(nMatches);
|
317 |
color.resize(nMatches);
|
321 |
for(int i=0; i<nMatches; i++){
|
318 |
for(int i=0; i<nMatches; i++){
|
322 |
|
319 |
|
323 |
cv::Vec3b c0 = color0Rect.at<cv::Vec3b>(q0[i][1], q0[i][0]);
|
320 |
cv::Vec3f c0 = color0Rect.at<cv::Vec3f>(q0[i][1], q0[i][0]);
|
324 |
cv::Vec3b c1 = color1Rect.at<cv::Vec3b>(q1[i][1], q1[i][0]);
|
321 |
cv::Vec3f c1 = color1Rect.at<cv::Vec3f>(q1[i][1], q1[i][0]);
|
325 |
// cv::Vec3b c0 = getColorSubpix(color0Rect, q0[i]);
|
322 |
// cv::Vec3b c0 = getColorSubpix(color0Rect, q0[i]);
|
326 |
// cv::Vec3b c1 = getColorSubpix(color1Rect, q0[i]);
|
323 |
// cv::Vec3b c1 = getColorSubpix(color1Rect, q0[i]);
|
327 |
|
324 |
|
328 |
color[i] = 0.5*c0 + 0.5*c1;
|
325 |
color[i] = 0.5*c0 + 0.5*c1;
|
329 |
}
|
326 |
}
|