Skip to content

Commit aa159f0

Browse files
author
Sai Vemprala
committed
Intermediate transfer commit - heavy WIP modules'
1 parent 13dfba3 commit aa159f0

10 files changed

+173
-77
lines changed

include/coloc/CPUMatcher.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace coloc
5656
bool matchMapFeatures(std::unique_ptr<features::AKAZE_Binary_Regions> &scene1, std::unique_ptr<features::AKAZE_Binary_Regions> &scene2, std::vector<IndMatch> &commonFeatures)
5757
{
5858
matching::DistanceRatioMatch(
59-
0.9, BRUTE_FORCE_HAMMING,
59+
0.8, BRUTE_FORCE_HAMMING,
6060
*scene1.get(),
6161
*scene2.get(),
6262
commonFeatures);

include/coloc/GPUMatcher.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace coloc
159159
commonFeatures = computeMatches(const_cast<unsigned int*>(static_cast<const unsigned int*>(map1->DescriptorRawData())),
160160
const_cast<unsigned int*>(static_cast<const unsigned int*>(map2->DescriptorRawData())),
161161
map1->RegionCount(),
162-
map2->RegionCount(), 70);
162+
map2->RegionCount(), 60);
163163
}
164164

165165
void computeMatchesPair(const Pair& pairIdx, FeatureMap& regions, IndMatches &putativeMatches)
@@ -186,10 +186,12 @@ namespace coloc
186186
const size_t sizeDTraining = (numKPTraining + 8) * 64; // D2 for descriptor2
187187

188188
gpuErrchk(cudaMemsetAsync(d_descT, 0, sizeDTraining, m_stream1));
189+
cudaStreamSynchronize(m_stream1);
189190
gpuErrchk(cudaMemcpyAsync(d_descT, h_descriptorsTraining, sizeDTraining, cudaMemcpyHostToDevice, m_stream1));
190191
cudaStreamSynchronize(m_stream1);
191192

192193
gpuErrchk(cudaMemsetAsync(d_descQ, 0, sizeDQuery, m_stream2));
194+
cudaStreamSynchronize(m_stream1);
193195
gpuErrchk(cudaMemcpyAsync(d_descQ, h_descriptorsQuery, sizeDQuery, cudaMemcpyHostToDevice, m_stream2));
194196
cudaStreamSynchronize(m_stream2);
195197

include/coloc/InterfaceDisk.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace coloc
1313
std::string number = std::string(4 - std::to_string(imageNumber).length(), '0') + std::to_string(imageNumber); //std::to_string(imageNumber); //std::string(4 - std::to_string(imageNumber).length(), '0') + std::to_string(imageNumber);
1414
data->filenames[id] = params->imageFolder + "img__Quad" + std::to_string(id) + "_" + number + ".png"; //"image (" + number + ").png";
1515
detector.detectFeaturesFile(id, data->regions, data->filenames[id]);
16+
data->scene.views[id].reset(new View(data->filenames[id], id, 0, id, params->imageSize.first, params->imageSize.second));
1617
}
1718

1819
void processImages(std::vector <int>& droneIds) override

include/coloc/KalmanFilter.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ namespace coloc
6060

6161
if (measurementsAvailable) {
6262
bool reject = chiSquareGating(droneId, droneMeasurements[droneId], predicted);
63-
//if (reject && !init) {
64-
// estimated = predicted;
65-
//}
66-
//else
67-
//{
63+
if (reject && !init) {
64+
estimated = predicted;
65+
}
66+
else
67+
{
6868
estimated = droneFilters[droneId].correct(droneMeasurements[droneId]);
69-
//}
69+
}
7070
}
7171
else {
7272
estimated = predicted;
@@ -106,7 +106,7 @@ namespace coloc
106106
{
107107
KF.init(nStates, nMeasurements, nInputs, CV_64F); // init Kalman Filter
108108
cv::setIdentity(KF.processNoiseCov, cv::Scalar::all(1e-5)); // set process noise
109-
cv::setIdentity(KF.measurementNoiseCov, cv::Scalar::all(1e-3)); // set measurement noise
109+
cv::setIdentity(KF.measurementNoiseCov, cv::Scalar::all(1e-4)); // set measurement noise
110110
cv::setIdentity(KF.errorCovPost, cv::Scalar::all(1)); // error covariance
111111

112112

include/coloc/Localizer.hpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ namespace coloc
143143
cv::eigen2cv(pose.rotation(), rvec);
144144
cv::Mat tvec = cv::Mat(1, 3, CV_32FC1, cv::Scalar::all(0));
145145

146-
tvec.at<float>(0, 0) = pose.center()[0];
147-
tvec.at<float>(0, 1) = pose.center()[1];
148-
tvec.at<float>(0, 2) = pose.center()[2];
146+
tvec.at<float>(0, 0) = pose.translation()[0];
147+
tvec.at<float>(0, 1) = pose.translation()[1];
148+
tvec.at<float>(0, 2) = pose.translation()[2];
149149

150150
cv::Mat Kcv = cv::Mat(3, 3, CV_32FC1, cv::Scalar::all(0));
151151
Kcv.at<float>(0, 0) = (*K)[idx](0, 0);
152-
Kcv.at<float>(0, 2) = (*K)[idx](0, 0);
153-
Kcv.at<float>(1, 1) = (*K)[idx](0, 2);
152+
Kcv.at<float>(0, 2) = (*K)[idx](0, 2);
153+
Kcv.at<float>(1, 1) = (*K)[idx](0, 0);
154154
Kcv.at<float>(1, 2) = (*K)[idx](1, 2);
155155
Kcv.at<float>(2, 2) = 1.0f;
156156

@@ -167,16 +167,18 @@ namespace coloc
167167
error += cv::norm(imagePoints[j] - reprojected[j]);
168168
}
169169

170+
rmse = error / reprojected.size();
171+
170172
cv::Mat Sigma = cv::Mat(J.t() * J, cv::Rect(0, 0, 6, 6)).inv();
171173
cv::Mat std_dev;
172174
sqrt(Sigma.diag(), std_dev);
173175
//std::cout << "Translation standard deviation:" << std::endl << std_dev.at<double>(3, 0) << std::endl << std_dev.at<double>(4, 0) << std::endl << std_dev.at<double>(5,0) << std::endl;
174176

175177
//std::cout << "Total standard deviation:" << std::endl << std_dev << std::endl;
176178

177-
poseCovariance[0][21] = std_dev.at<double>(3, 0);
178-
poseCovariance[0][28] = std_dev.at<double>(4, 0);
179-
poseCovariance[0][35] = std_dev.at<double>(5, 0);
179+
//poseCovariance[0][21] = std_dev.at<double>(3, 0);
180+
//poseCovariance[0][28] = std_dev.at<double>(4, 0);
181+
//poseCovariance[0][35] = std_dev.at<double>(5, 0);
180182

181183
return refineStatus;
182184
}

include/coloc/Reconstructor.hpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace coloc
4444
{ }
4545

4646
void reconstructScene(bool inter, colocData& data, std::vector <Pose3>, float, bool);
47+
void Reconstructor::interReconstruct(int sourceId, int destId, colocData& data);
4748

4849
private:
4950
// Internal methods
@@ -76,6 +77,28 @@ namespace coloc
7677
Scene* scene;
7778
};
7879

80+
void Reconstructor::interReconstruct(int sourceId, int destId, colocData& data)
81+
{
82+
this->regionsRCT = &data.regions;
83+
this->matchesRCT = &data.geometricMatches;
84+
this->relativePosesRCT = &data.relativePoses;
85+
this->scene = &data.tempScene;
86+
87+
88+
float scale = 1.0;
89+
Pair seedPair = std::make_pair(sourceId, destId);
90+
91+
std::cout << "Using pair " << seedPair.first << " & " << seedPair.second << "as seed" << std::endl;
92+
93+
data.keyframeIdx = seedPair.first;
94+
initializeTracks(seedPair);
95+
initializeScene(imageSize->first, imageSize->second, seedPair);
96+
97+
std::cout << "Triangulating feature matches... ";
98+
triangulatePoints(seedPair, Pose3(Mat3::Identity(), Vec3::Zero()), scale);
99+
std::cout << "Done." << std::endl;
100+
}
101+
79102
void Reconstructor::reconstructScene(bool inter, colocData& data, std::vector <Pose3> poses, float scale = 1.0, bool Adjust = false)
80103
{
81104
this->regionsRCT = &data.regions;
@@ -183,8 +206,8 @@ namespace coloc
183206
const uint32_t i = iter->second;
184207
const uint32_t j = (++iter)->second;
185208

186-
const Vec2 x1_ = regionsRCT->at(pair.first)->GetRegionsPositions()[i].coords().cast<double>();
187-
const Vec2 x2_ = regionsRCT->at(pair.second)->GetRegionsPositions()[j].coords().cast<double>();
209+
const Vec2 x1_ = camCurrent->get_ud_pixel(regionsRCT->at(pair.first)->GetRegionsPositions()[i].coords().cast<double>());
210+
const Vec2 x2_ = cam_J->get_ud_pixel(regionsRCT->at(pair.second)->GetRegionsPositions()[j].coords().cast<double>());
188211

189212
Vec3 X;
190213

@@ -203,7 +226,7 @@ namespace coloc
203226
if (Pose_I.depth(X) < 0 && Pose_J.depth(X) < 0)
204227
continue;
205228

206-
if (std::abs(X[2]) > 1000.0)
229+
if (std::abs(X[2]) > 100.0)
207230
continue;
208231

209232
Observations obs;

include/coloc/RobustMatcher.hpp

+59-24
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace coloc
160160

161161
using KernelType = robust::ACKernelAdaptorEssential<
162162
openMVG::essential::kernel::FivePointSolver,
163-
openMVG::fundamental::kernel::EpipolarDistanceError,
163+
openMVG::fundamental::kernel::SymmetricEpipolarDistanceError,
164164
Mat3>;
165165
KernelType kernel(x1, norm2Dpt_1, params.imageSize.first, params.imageSize.second,
166166
x2, norm2Dpt_2, params.imageSize.first, params.imageSize.second,
@@ -170,7 +170,7 @@ namespace coloc
170170
const auto ACRansacOut = ACRANSAC(kernel, relativePose_info.vec_inliers, iterationCount, &relativePose_info.essential_matrix,
171171
relativePose_info.initial_residual_tolerance, false);
172172

173-
relativePose_info.found_residual_precision = 5.0;
173+
relativePose_info.found_residual_precision = ACRansacOut.first;
174174

175175
if (relativePose_info.vec_inliers.size() < 2.5 * KernelType::Solver::MINIMUM_SAMPLES)
176176
return EXIT_FAILURE;
@@ -243,9 +243,8 @@ namespace coloc
243243
std::vector <IndMatch> putativeMatches, filteredMatches;
244244

245245
putativeMatches = commonFeatures;
246-
247246
commonFeatures.clear();
248-
247+
/*
249248
const PointFeatures featI = scene1->GetRegionsPositions();
250249
const PointFeatures featJ = scene2->GetRegionsPositions();
251250
@@ -291,7 +290,8 @@ namespace coloc
291290
// *scene1.get(),
292291
// *scene2.get(),
293292
// putativeMatches);
294-
/*
293+
*/
294+
295295
const PointFeatures featI = scene1->GetRegionsPositions();
296296
const PointFeatures featJ = scene2->GetRegionsPositions();
297297

@@ -344,7 +344,7 @@ namespace coloc
344344
std::cout << "Right coordinates: " << xR.col(k) << std::endl;
345345
346346
}
347-
347+
*/
348348
inliers.push_back(putativeMatches[k]);
349349
myfile << res(0, 0) << "," << xL(0, k) << "," << xL(1, k) << "," << xR(0, k) << "," << xR(1, k) << std::endl;
350350
epipolarLineDeviations.push_back(std::abs(res(0, 0)));
@@ -358,16 +358,18 @@ namespace coloc
358358

359359
std::sort(std::begin(matchIndices), std::end(matchIndices), [&](int i1, int i2) { return epipolarLineDeviations[i1] < epipolarLineDeviations[i2]; });
360360
std::sort(epipolarLineDeviations.begin(), epipolarLineDeviations.end());
361-
//for (int ic = 0; ic < inliers.size(); ++ic)
362-
// commonFeatures.push_back(inliers[ic]);
363-
364-
for (int ic = 0; ic < 2; ic++)
365-
commonFeatures.push_back(putativeMatches[matchIndices[ic]]);
361+
for (int ic = 0; ic < inliers.size(); ++ic)
362+
commonFeatures.push_back(inliers[ic]);
363+
/*
364+
if (matchIndices.size() != 0) {
365+
for (int ic = 0; ic < 2; ic++)
366+
commonFeatures.push_back(putativeMatches[matchIndices[ic]]);
367+
}
366368
*/
367369
return EXIT_SUCCESS;
368370
}
369371

370-
std::unique_ptr <RelativePose_Info> computeRelativePose(Pair current_pair, FeatureMap& regions, PairWiseMatches& putativeMatches)
372+
bool computeRelativePose(RelativePose_Info& relativePose, Pair current_pair, FeatureMap& regions, PairWiseMatches& putativeMatches)
371373
{
372374
const uint32_t I = std::min(current_pair.first, current_pair.second);
373375
const uint32_t J = std::max(current_pair.first, current_pair.second);
@@ -378,12 +380,7 @@ namespace coloc
378380
std::vector <IndMatch> pairMatches = putativeMatches[current_pair];
379381
Mat xL(2, pairMatches.size());
380382
Mat xR(2, pairMatches.size());
381-
for (size_t k = 0; k < pairMatches.size(); ++k) {
382-
xL.col(k) = featI[pairMatches[k].i_].coords().cast<double>();
383-
xR.col(k) = featJ[pairMatches[k].j_].coords().cast<double>();
384-
}
385-
386-
RelativePose_Info relativePose;
383+
387384

388385
const openMVG::cameras::Pinhole_Intrinsic_Radial_K3
389386
camL(params->imageSize.first, params->imageSize.second, (params->K[current_pair.first])(0, 0), (params->K[current_pair.first])(0, 2), (params->K[current_pair.first])(1, 2),
@@ -393,6 +390,13 @@ namespace coloc
393390

394391
bool status, findPose = true;
395392

393+
for (size_t k = 0; k < pairMatches.size(); ++k) {
394+
xL.col(k) = featI[pairMatches[k].i_].coords().cast<double>();
395+
xL.col(k) = camL.get_ud_pixel(xL.col(k));
396+
xR.col(k) = featJ[pairMatches[k].j_].coords().cast<double>();
397+
xR.col(k) = camR.get_ud_pixel(xR.col(k));
398+
}
399+
396400
if (params->model == 'H')
397401
status = filterHomography(&camL, &camR, xL, xR, relativePose, *params, findPose);
398402
else if (params->model == 'E')
@@ -416,19 +420,50 @@ namespace coloc
416420
<< std::endl;
417421
}
418422

419-
return std::make_unique<RelativePose_Info>(relativePose);
423+
return status;
424+
}
425+
426+
bool filterMatchesPair(Pair currentPair, FeatureMap& regions, PairWiseMatches& putativeMatches, PairWiseMatches& geometricMatches, InterPoseMap& relativePoses)
427+
{
428+
std::vector <IndMatch> pairMatches = putativeMatches[currentPair];
429+
RelativePose_Info relativePose;
430+
431+
bool status = computeRelativePose(relativePose, currentPair, regions, putativeMatches);
432+
433+
std::vector <IndMatch> vec_geometricMatches;
434+
for (int ic = 0; ic < relativePose.vec_inliers.size(); ++ic)
435+
vec_geometricMatches.push_back(pairMatches[relativePose.vec_inliers[ic]]);
436+
437+
if (!vec_geometricMatches.empty())
438+
{
439+
PairWiseMatches::iterator it = geometricMatches.find(currentPair);
440+
if (geometricMatches.end() != it)
441+
geometricMatches.at(currentPair) = vec_geometricMatches;
442+
else
443+
geometricMatches.insert({ { currentPair.first, currentPair.second }, std::move(vec_geometricMatches) });
444+
}
445+
446+
InterPoseMap::iterator it = relativePoses.find(currentPair);
447+
if (relativePoses.end() != it)
448+
relativePoses.at(currentPair) = relativePose;
449+
else
450+
relativePoses.insert({ { currentPair.first, currentPair.second }, std::move(relativePose) });
451+
452+
return status;
420453
}
421454

422455
void filterMatches(FeatureMap& regions, PairWiseMatches& putativeMatches, PairWiseMatches& geometricMatches, InterPoseMap& relativePoses)
423456
{
424457
for (const auto matchedPair : putativeMatches) {
425458
Pair currentPair = matchedPair.first;
426459
std::vector <IndMatch> pairMatches = putativeMatches[currentPair];
427-
std::unique_ptr<RelativePose_Info> relativePose = computeRelativePose(matchedPair.first, regions, putativeMatches);
460+
RelativePose_Info relativePose;
461+
462+
bool status = computeRelativePose(relativePose, matchedPair.first, regions, putativeMatches);
428463

429464
std::vector <IndMatch> vec_geometricMatches;
430-
for (int ic = 0; ic < relativePose->vec_inliers.size(); ++ic)
431-
vec_geometricMatches.push_back(pairMatches[relativePose->vec_inliers[ic]]);
465+
for (int ic = 0; ic < relativePose.vec_inliers.size(); ++ic)
466+
vec_geometricMatches.push_back(pairMatches[relativePose.vec_inliers[ic]]);
432467

433468
if (!vec_geometricMatches.empty())
434469
{
@@ -441,9 +476,9 @@ namespace coloc
441476

442477
InterPoseMap::iterator it = relativePoses.find(currentPair);
443478
if (relativePoses.end() != it)
444-
relativePoses.at(currentPair) = *relativePose;
479+
relativePoses.at(currentPair) = relativePose;
445480
else
446-
relativePoses.insert({ { currentPair.first, currentPair.second }, std::move(*relativePose) });
481+
relativePoses.insert({ { currentPair.first, currentPair.second }, std::move(relativePose) });
447482
}
448483
}
449484
};

0 commit comments

Comments
 (0)