-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathrpvio.patch
5856 lines (5358 loc) · 245 KB
/
rpvio.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 3d295e1ff4c292ce203e636f363520f9b633908c Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Thu, 17 Sep 2020 12:22:47 +0530
Subject: [PATCH 01/42] Add code for homography-based initializatin
---
vins_estimator/src/estimator.cpp | 14 ++--
vins_estimator/src/initial/solve_5pts.cpp | 80 ++++++++++++++++++-----
vins_estimator/src/initial/solve_5pts.h | 6 +-
3 files changed, 73 insertions(+), 27 deletions(-)
diff --git a/vins_estimator/src/estimator.cpp b/vins_estimator/src/estimator.cpp
index cb7a4af..46c93ef 100644
--- a/vins_estimator/src/estimator.cpp
+++ b/vins_estimator/src/estimator.cpp
@@ -491,14 +491,16 @@ bool Estimator::relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, int &l
}
average_parallax = 1.0 * sum_parallax / int(corres.size());
- MatrixXd::Identity(4,4) TrIC;
- TrIC.block(0, 0, 3, 3) = RIC;
- TrIC.col(3) = TIC;
+ Matrix4d TrIC = Matrix4d::Identity();
+ TrIC.block(0, 0, 3, 3) = RIC[0];
+ TrIC.block(0,3,3,0) = TIC[0];
- //compute preintegrated rotation
-
+ //compute corresponding preintegrated rotation
+ Matrix3d R_imu = Matrix3d::Identity();
+ for(int k = WINDOW_SIZE - 1; k > i; k--)
+ R_imu = R_imu * (pre_integrations[k]->delta_q).toRotationMatrix();
- if(average_parallax * 660 > 30 && m_estimator.solveRelativeHRT(corres, relative_R, relative_T, R_imu, TrIC))
+ if(average_parallax * 660 > 30 && m_estimator.solveRelativeHRT(corres, R_imu, TrIC, relative_R, relative_T))
{
l = i;
ROS_DEBUG("average_parallax %f choose l %d and newest frame to triangulate the whole structure", average_parallax * 460, l);
diff --git a/vins_estimator/src/initial/solve_5pts.cpp b/vins_estimator/src/initial/solve_5pts.cpp
index a1c170d..61440da 100644
--- a/vins_estimator/src/initial/solve_5pts.cpp
+++ b/vins_estimator/src/initial/solve_5pts.cpp
@@ -1,4 +1,5 @@
#include "solve_5pts.h"
+#include <algorithm>
namespace cv {
@@ -241,27 +242,70 @@ bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &c
cv::Mat H = cv::findHomography(ll, rr, cv::RANSAC, 0.3/665);
cv::Mat K = (cv::Mat_<double>(3, 3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
- decomposeH(H, K, R_imu, TIC);
-
- Eigen::Matrix3d R;
- Eigen::Vector3d T;
- for (int i = 0; i < 3; i++)
- {
- T(i) = trans.at<double>(i, 0);
- for (int j = 0; j < 3; j++)
- R(i, j) = rot.at<double>(i, j);
- }
-
- Rotation = R.transpose();
- Translation = -R.transpose() * T;
- if(inlier_cnt > 12)
- return true;
- else
- return false;
+ Eigen::Matrix4d Tr = decomposeH(H, K, R_imu, TrIC);
+ Rotation = Tr.block(0,0,3,3);
+ Translation = Tr.block(0,3,3,0);
+ return true;
}
return false;
}
-void MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC)
+Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC)
{
+ vector<cv::Mat> cv_Rs, cv_ts, cv_ns;
+ int n_sols = cv::decomposeHomographyMat(H, K, cv_Rs, cv_ts, cv_ns);
+
+ vector<Matrix4d> positive_depth_transforms;
+ if(n_sols > 1)
+ {
+ for(int i = 0; i < n_sols; i++)
+ {
+ Matrix4d Tr = Matrix4d::Identity();
+ Matrix3d R;
+ cv::cv2eigen(cv_Rs[i], R);
+ Tr.block(0,0,3,3) = R;
+
+ Vector3d t;
+ cv::cv2eigen(cv_ts[i], t);
+ Tr.block(0,3,3,0) = t;
+
+ //Tr = TrIC * Tr * TrIC.inverse();
+ Tr = Tr.inverse();
+
+ Vector3d e3(0, 0, 1);
+ Vector3d n;
+ cv::cv2eigen(cv_ns[i], n);
+ if(n.dot(e3) > 0)
+ positive_depth_transforms.push_back(Tr);
+ }
+
+ vector<double> rot_diff;
+ for(size_t i = 0; i < positive_depth_transforms.size(); i++)
+ {
+ Eigen::Matrix4d Tr = TrIC * positive_depth_transforms[i] * TrIC.inverse();
+ Eigen::Matrix3d R = Tr.block(0,0,3,3);
+ double f = (R.transpose()*R_imu - MatrixXd::Identity(3,3)).norm();
+ rot_diff.push_back(f);
+ }
+
+ int min_index = std::min_element(rot_diff.begin(), rot_diff.end()) - rot_diff.begin();
+ Matrix4d Tr = positive_depth_transforms[min_index];
+ return Tr;
+ }
+
+ else
+ {
+ Matrix4d Tr = Matrix4d::Identity();
+ Matrix3d R;
+ cv::cv2eigen(cv_Rs[0], R);
+ Tr.block(0,0,3,3) = R;
+
+ Vector3d t;
+ cv::cv2eigen(cv_ts[0], t);
+ Tr.block(0,3,3,0) = t;
+
+ //Tr = TrIC * Tr * TrIC.inverse();
+ Tr = Tr.inverse();
+ return Tr;
+ }
}
diff --git a/vins_estimator/src/initial/solve_5pts.h b/vins_estimator/src/initial/solve_5pts.h
index 3e95c9e..9fb118e 100644
--- a/vins_estimator/src/initial/solve_5pts.h
+++ b/vins_estimator/src/initial/solve_5pts.h
@@ -4,8 +4,8 @@
using namespace std;
#include <opencv2/opencv.hpp>
-//#include <opencv2/core/eigen.hpp>
#include <eigen3/Eigen/Dense>
+#include <opencv2/core/eigen.hpp>
using namespace Eigen;
#include <ros/console.h>
@@ -15,8 +15,8 @@ class MotionEstimator
public:
bool solveRelativeRT(const vector<pair<Vector3d, Vector3d>> &corres, Matrix3d &R, Vector3d &T);
- bool solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, const Matrix3d &R, Vector3d &T);
- void decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC);
+ bool solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &R, Vector3d &T);
+ Matrix4d decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC);
private:
double testTriangulation(const vector<cv::Point2f> &l,
--
2.17.1
From 56f9ef55ba6caf95001bba4e8cd34524fd79a089 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Thu, 17 Sep 2020 14:19:09 +0530
Subject: [PATCH 02/42] Fix runtime errors
---
vins_estimator/src/estimator.cpp | 4 ++--
vins_estimator/src/initial/solve_5pts.cpp | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/vins_estimator/src/estimator.cpp b/vins_estimator/src/estimator.cpp
index 46c93ef..733a968 100644
--- a/vins_estimator/src/estimator.cpp
+++ b/vins_estimator/src/estimator.cpp
@@ -492,8 +492,8 @@ bool Estimator::relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, int &l
average_parallax = 1.0 * sum_parallax / int(corres.size());
Matrix4d TrIC = Matrix4d::Identity();
- TrIC.block(0, 0, 3, 3) = RIC[0];
- TrIC.block(0,3,3,0) = TIC[0];
+ TrIC.block(0,0,3,3) = ric[0];
+ TrIC.block(0,3,3,1) = tic[0];
//compute corresponding preintegrated rotation
Matrix3d R_imu = Matrix3d::Identity();
diff --git a/vins_estimator/src/initial/solve_5pts.cpp b/vins_estimator/src/initial/solve_5pts.cpp
index 61440da..6be2bf1 100644
--- a/vins_estimator/src/initial/solve_5pts.cpp
+++ b/vins_estimator/src/initial/solve_5pts.cpp
@@ -244,7 +244,7 @@ bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &c
Eigen::Matrix4d Tr = decomposeH(H, K, R_imu, TrIC);
Rotation = Tr.block(0,0,3,3);
- Translation = Tr.block(0,3,3,0);
+ Translation = Tr.block(0,3,3,1);
return true;
}
return false;
@@ -267,10 +267,10 @@ Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const M
Vector3d t;
cv::cv2eigen(cv_ts[i], t);
- Tr.block(0,3,3,0) = t;
+ Tr.block(0,3,3,1) = t;
//Tr = TrIC * Tr * TrIC.inverse();
- Tr = Tr.inverse();
+ Tr = Tr.inverse().eval();
Vector3d e3(0, 0, 1);
Vector3d n;
@@ -302,10 +302,10 @@ Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const M
Vector3d t;
cv::cv2eigen(cv_ts[0], t);
- Tr.block(0,3,3,0) = t;
+ Tr.block(0,3,3,1) = t;
//Tr = TrIC * Tr * TrIC.inverse();
- Tr = Tr.inverse();
+ Tr = Tr.inverse().eval();
return Tr;
}
}
--
2.17.1
From f9db6ec5f6d62bc608e5acd96c45414f384eadc4 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Sat, 19 Sep 2020 08:21:32 +0530
Subject: [PATCH 03/42] Reject with H
---
feature_tracker/src/feature_tracker.cpp | 3 ++-
vins_estimator/src/initial/solve_5pts.cpp | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/feature_tracker/src/feature_tracker.cpp b/feature_tracker/src/feature_tracker.cpp
index d33709c..41322b8 100644
--- a/feature_tracker/src/feature_tracker.cpp
+++ b/feature_tracker/src/feature_tracker.cpp
@@ -188,7 +188,8 @@ void FeatureTracker::rejectWithF()
}
vector<uchar> status;
- cv::findFundamentalMat(un_cur_pts, un_forw_pts, cv::FM_RANSAC, F_THRESHOLD, 0.99, status);
+ //cv::findFundamentalMat(un_cur_pts, un_forw_pts, cv::FM_RANSAC, F_THRESHOLD, 0.99, status);
+ cv::findHomography(un_cur_pts, un_forw_pts, cv::RANSAC, 3, status);
int size_a = cur_pts.size();
reduceVector(prev_pts, status);
reduceVector(cur_pts, status);
diff --git a/vins_estimator/src/initial/solve_5pts.cpp b/vins_estimator/src/initial/solve_5pts.cpp
index 6be2bf1..50999c3 100644
--- a/vins_estimator/src/initial/solve_5pts.cpp
+++ b/vins_estimator/src/initial/solve_5pts.cpp
@@ -227,6 +227,7 @@ bool MotionEstimator::solveRelativeRT(const vector<pair<Vector3d, Vector3d>> &co
return false;
}
+
bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &Rotation, Vector3d &Translation)
{
if (corres.size() >= 15)
@@ -241,6 +242,7 @@ bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &c
//cv::Mat E = cv::findFundamentalMat(ll, rr, cv::FM_RANSAC, 0.3 / 460, 0.99, mask);
cv::Mat H = cv::findHomography(ll, rr, cv::RANSAC, 0.3/665);
cv::Mat K = (cv::Mat_<double>(3, 3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
+ //cv::Mat K = (cv::Mat_<double>(3,3) << 665, 0, 511, 0, 665, 383, 0, 0, 1);
Eigen::Matrix4d Tr = decomposeH(H, K, R_imu, TrIC);
Rotation = Tr.block(0,0,3,3);
@@ -250,6 +252,7 @@ bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &c
return false;
}
+
Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC)
{
vector<cv::Mat> cv_Rs, cv_ts, cv_ns;
--
2.17.1
From 64247beda4b05f162fbec72127dd1f79bade8709 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Tue, 22 Sep 2020 10:39:26 +0530
Subject: [PATCH 04/42] Add code for homography-constrained visual BA for init
---
vins_estimator/src/estimator.cpp | 11 +-
vins_estimator/src/estimator.h | 2 +-
vins_estimator/src/initial/initial_sfm.cpp | 216 ++++++++++++++++++++-
vins_estimator/src/initial/initial_sfm.h | 40 +++-
vins_estimator/src/initial/solve_5pts.cpp | 27 ++-
vins_estimator/src/initial/solve_5pts.h | 4 +-
6 files changed, 280 insertions(+), 20 deletions(-)
diff --git a/vins_estimator/src/estimator.cpp b/vins_estimator/src/estimator.cpp
index 733a968..c561fd6 100644
--- a/vins_estimator/src/estimator.cpp
+++ b/vins_estimator/src/estimator.cpp
@@ -267,15 +267,16 @@ bool Estimator::initialStructure()
}
Matrix3d relative_R;
Vector3d relative_T;
+ Vector3d n;
int l;
- if (!relativeHPose(relative_R, relative_T, l))
+ if (!relativeHPose(relative_R, relative_T, n, l))
{
ROS_INFO("Not enough features or parallax; Move device around");
return false;
}
GlobalSFM sfm;
- if(!sfm.construct(frame_count + 1, Q, T, l,
- relative_R, relative_T,
+ if(!sfm.constructH(frame_count + 1, Q, T, l,
+ relative_R, relative_T, n,
sfm_f, sfm_tracked_points))
{
ROS_DEBUG("global SFM failed!");
@@ -470,7 +471,7 @@ bool Estimator::relativePose(Matrix3d &relative_R, Vector3d &relative_T, int &l)
return false;
}
-bool Estimator::relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, int &l)
+bool Estimator::relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, Vector3d &n, int &l)
{
// find previous frame which contains enough correspondence and parallex with newest frame
for (int i = 0; i < WINDOW_SIZE; i++)
@@ -500,7 +501,7 @@ bool Estimator::relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, int &l
for(int k = WINDOW_SIZE - 1; k > i; k--)
R_imu = R_imu * (pre_integrations[k]->delta_q).toRotationMatrix();
- if(average_parallax * 660 > 30 && m_estimator.solveRelativeHRT(corres, R_imu, TrIC, relative_R, relative_T))
+ if(average_parallax * 660 > 30 && m_estimator.solveRelativeHRT(corres, R_imu, TrIC, relative_R, relative_T, n))
{
l = i;
ROS_DEBUG("average_parallax %f choose l %d and newest frame to triangulate the whole structure", average_parallax * 460, l);
diff --git a/vins_estimator/src/estimator.h b/vins_estimator/src/estimator.h
index 7f912da..9b2a731 100644
--- a/vins_estimator/src/estimator.h
+++ b/vins_estimator/src/estimator.h
@@ -40,7 +40,7 @@ class Estimator
bool initialStructure();
bool visualInitialAlign();
bool relativePose(Matrix3d &relative_R, Vector3d &relative_T, int &l);
- bool relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, int &l);
+ bool relativeHPose(Matrix3d &relative_R, Vector3d &relative_T, Vector3d &n, int &l);
void slideWindow();
void solveOdometry();
void slideWindowNew();
diff --git a/vins_estimator/src/initial/initial_sfm.cpp b/vins_estimator/src/initial/initial_sfm.cpp
index 6fbcc17..c7b1661 100644
--- a/vins_estimator/src/initial/initial_sfm.cpp
+++ b/vins_estimator/src/initial/initial_sfm.cpp
@@ -280,11 +280,11 @@ bool GlobalSFM::construct(int frame_num, Quaterniond* q, Vector3d* T, int l,
//std::cout << summary.BriefReport() << "\n";
if (summary.termination_type == ceres::CONVERGENCE || summary.final_cost < 5e-03)
{
- //cout << "vision only BA converge" << endl;
+ cout << "vision only BA converge" << endl;
}
else
{
- //cout << "vision only BA not converge " << endl;
+ cout << "vision only BA not converge " << endl;
return false;
}
for (int i = 0; i < frame_num; i++)
@@ -311,3 +311,215 @@ bool GlobalSFM::construct(int frame_num, Quaterniond* q, Vector3d* T, int l,
}
+
+bool GlobalSFM::constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
+ const Matrix3d relative_R, const Vector3d relative_T, const Vector3d n,
+ vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points)
+{
+ feature_num = sfm_f.size();
+ //cout << "set 0 and " << l << " as known " << endl;
+ // have relative_r relative_t
+ // intial two view
+ q[l].w() = 1;
+ q[l].x() = 0;
+ q[l].y() = 0;
+ q[l].z() = 0;
+ T[l].setZero();
+ q[frame_num - 1] = q[l] * Quaterniond(relative_R);
+ T[frame_num - 1] = relative_T;
+ //cout << "init q_l " << q[l].w() << " " << q[l].vec().transpose() << endl;
+ //cout << "init t_l " << T[l].transpose() << endl;
+
+ //rotate to cam frame
+ Matrix3d c_Rotation[frame_num];
+ Vector3d c_Translation[frame_num];
+ Quaterniond c_Quat[frame_num];
+ double c_rotation[frame_num][4];
+ double c_translation[frame_num][3];
+ double c_normal[3];
+ Eigen::Matrix<double, 3, 4> Pose[frame_num];
+
+ c_Quat[l] = q[l].inverse();
+ c_Rotation[l] = c_Quat[l].toRotationMatrix();
+ c_Translation[l] = -1 * (c_Rotation[l] * T[l]);
+ Pose[l].block<3, 3>(0, 0) = c_Rotation[l];
+ Pose[l].block<3, 1>(0, 3) = c_Translation[l];
+
+ c_Quat[frame_num - 1] = q[frame_num - 1].inverse();
+ c_Rotation[frame_num - 1] = c_Quat[frame_num - 1].toRotationMatrix();
+ c_Translation[frame_num - 1] = -1 * (c_Rotation[frame_num - 1] * T[frame_num - 1]);
+ Pose[frame_num - 1].block<3, 3>(0, 0) = c_Rotation[frame_num - 1];
+ Pose[frame_num - 1].block<3, 1>(0, 3) = c_Translation[frame_num - 1];
+
+ //1: trangulate between l ----- frame_num - 1
+ //2: solve pnp l + 1; trangulate l + 1 ------- frame_num - 1;
+ for (int i = l; i < frame_num - 1 ; i++)
+ {
+ // solve pnp
+ if (i > l)
+ {
+ Matrix3d R_initial = c_Rotation[i - 1];
+ Vector3d P_initial = c_Translation[i - 1];
+ if(!solveFrameByPnP(R_initial, P_initial, i, sfm_f))
+ return false;
+ c_Rotation[i] = R_initial;
+ c_Translation[i] = P_initial;
+ c_Quat[i] = c_Rotation[i];
+ Pose[i].block<3, 3>(0, 0) = c_Rotation[i];
+ Pose[i].block<3, 1>(0, 3) = c_Translation[i];
+ }
+
+ // triangulate point based on the solve pnp result
+ triangulateTwoFrames(i, Pose[i], frame_num - 1, Pose[frame_num - 1], sfm_f);
+ }
+ //3: triangulate l-----l+1 l+2 ... frame_num -2
+ for (int i = l + 1; i < frame_num - 1; i++)
+ triangulateTwoFrames(l, Pose[l], i, Pose[i], sfm_f);
+ //4: solve pnp l-1; triangulate l-1 ----- l
+ // l-2 l-2 ----- l
+ for (int i = l - 1; i >= 0; i--)
+ {
+ //solve pnp
+ Matrix3d R_initial = c_Rotation[i + 1];
+ Vector3d P_initial = c_Translation[i + 1];
+ if(!solveFrameByPnP(R_initial, P_initial, i, sfm_f))
+ return false;
+ c_Rotation[i] = R_initial;
+ c_Translation[i] = P_initial;
+ c_Quat[i] = c_Rotation[i];
+ Pose[i].block<3, 3>(0, 0) = c_Rotation[i];
+ Pose[i].block<3, 1>(0, 3) = c_Translation[i];
+ //triangulate
+ triangulateTwoFrames(i, Pose[i], l, Pose[l], sfm_f);
+ }
+ //5: triangulate all other points
+ for (int j = 0; j < feature_num; j++)
+ {
+ if (sfm_f[j].state == true)
+ continue;
+ if ((int)sfm_f[j].observation.size() >= 2)
+ {
+ Vector2d point0, point1;
+ int frame_0 = sfm_f[j].observation[0].first;
+ point0 = sfm_f[j].observation[0].second;
+ int frame_1 = sfm_f[j].observation.back().first;
+ point1 = sfm_f[j].observation.back().second;
+ Vector3d point_3d;
+ triangulatePoint(Pose[frame_0], Pose[frame_1], point0, point1, point_3d);
+ sfm_f[j].state = true;
+ sfm_f[j].position[0] = point_3d(0);
+ sfm_f[j].position[1] = point_3d(1);
+ sfm_f[j].position[2] = point_3d(2);
+ //cout << "trangulated : " << frame_0 << " " << frame_1 << " 3d point : " << j << " " << point_3d.transpose() << endl;
+ }
+ }
+
+/*
+ for (int i = 0; i < frame_num; i++)
+ {
+ q[i] = c_Rotation[i].transpose();
+ cout << "solvePnP q" << " i " << i <<" " <<q[i].w() << " " << q[i].vec().transpose() << endl;
+ }
+ for (int i = 0; i < frame_num; i++)
+ {
+ Vector3d t_tmp;
+ t_tmp = -1 * (q[i] * c_Translation[i]);
+ cout << "solvePnP t" << " i " << i <<" " << t_tmp.x() <<" "<< t_tmp.y() <<" "<< t_tmp.z() << endl;
+ }
+*/
+ //full BA
+ ceres::Problem problem;
+ ceres::LocalParameterization* local_parameterization = new ceres::QuaternionParameterization();
+ //cout << " begin full BA " << endl;
+ for (int i = 0; i < frame_num; i++)
+ {
+ //double array for ceres
+ c_translation[i][0] = c_Translation[i].x();
+ c_translation[i][1] = c_Translation[i].y();
+ c_translation[i][2] = c_Translation[i].z();
+ c_rotation[i][0] = c_Quat[i].w();
+ c_rotation[i][1] = c_Quat[i].x();
+ c_rotation[i][2] = c_Quat[i].y();
+ c_rotation[i][3] = c_Quat[i].z();
+ problem.AddParameterBlock(c_rotation[i], 4, local_parameterization);
+ problem.AddParameterBlock(c_translation[i], 3);
+ if (i == l)
+ {
+ problem.SetParameterBlockConstant(c_rotation[i]);
+ }
+ if (i == l || i == frame_num - 1)
+ {
+ problem.SetParameterBlockConstant(c_translation[i]);
+ }
+ }
+
+ c_normal[0] = n[0];
+ c_normal[1] = n[1];
+ c_normal[2] = n[2];
+ problem.AddParameterBlock(c_normal, 3);
+
+ for (int i = 0; i < feature_num; i++)
+ {
+ if (sfm_f[i].state != true)
+ continue;
+ for (int j = 0; j < int(sfm_f[i].observation.size()); j++)
+ {
+ int l = sfm_f[i].observation[j].first;
+
+ ceres::CostFunction* b_cost_function = ReprojectionError3D::Create(
+ sfm_f[i].observation[j].second.x(),
+ sfm_f[i].observation[j].second.y());
+
+ problem.AddResidualBlock(b_cost_function, NULL, c_rotation[l], c_translation[l],
+ sfm_f[i].position);
+
+ ceres::CostFunction* h_cost_function = ReprojectionErrorH::Create(
+ sfm_f[i].observation[j].second.x(),
+ sfm_f[i].observation[j].second.y());
+
+ problem.AddResidualBlock(h_cost_function, NULL, c_rotation[l], c_translation[l],c_normal,
+ sfm_f[i].position);
+ }
+
+ }
+ ceres::Solver::Options options;
+ options.linear_solver_type = ceres::DENSE_SCHUR;
+ //options.minimizer_progress_to_stdout = true;
+ options.max_solver_time_in_seconds = 0.2;
+ ceres::Solver::Summary summary;
+ ceres::Solve(options, &problem, &summary);
+ //std::cout << summary.BriefReport() << "\n";
+ if (summary.termination_type == ceres::CONVERGENCE || summary.final_cost < 5e-03)
+ {
+ cout << "vision only BA converge" << endl;
+ }
+ else
+ {
+ cout << "vision only BA not converge " << endl;
+ return false;
+ }
+ for (int i = 0; i < frame_num; i++)
+ {
+ q[i].w() = c_rotation[i][0];
+ q[i].x() = c_rotation[i][1];
+ q[i].y() = c_rotation[i][2];
+ q[i].z() = c_rotation[i][3];
+ q[i] = q[i].inverse();
+ //cout << "final q" << " i " << i <<" " <<q[i].w() << " " << q[i].vec().transpose() << endl;
+ }
+ for (int i = 0; i < frame_num; i++)
+ {
+
+ T[i] = -1 * (q[i] * Vector3d(c_translation[i][0], c_translation[i][1], c_translation[i][2]));
+ //cout << "final t" << " i " << i <<" " << T[i](0) <<" "<< T[i](1) <<" "<< T[i](2) << endl;
+ }
+ for (int i = 0; i < (int)sfm_f.size(); i++)
+ {
+ if(sfm_f[i].state)
+ sfm_tracked_points[sfm_f[i].id] = Vector3d(sfm_f[i].position[0], sfm_f[i].position[1], sfm_f[i].position[2]);
+ }
+ return true;
+
+}
+
+
diff --git a/vins_estimator/src/initial/initial_sfm.h b/vins_estimator/src/initial/initial_sfm.h
index f70432d..a1e6854 100644
--- a/vins_estimator/src/initial/initial_sfm.h
+++ b/vins_estimator/src/initial/initial_sfm.h
@@ -53,6 +53,40 @@ struct ReprojectionError3D
double observed_v;
};
+
+struct ReprojectionErrorH
+{
+ ReprojectionErrorH(double observed_u, double observed_v)
+ :observed_u(observed_u), observed_v(observed_v)
+ {}
+
+ template <typename T>
+ bool operator()(const T* const R, const T* const t, const T* const n, const T* point, T* residuals) const
+ {
+ T p[3];
+ ceres::QuaternionRotatePoint(R, point, p);
+ T np = n[0] * point[0] + n[1] * point[1] + n[2] * point[2];
+ p[0] += t[0]*np; p[1] += t[1]*np; p[2] += t[2]*np;
+ T xp = p[0] / p[2];
+ T yp = p[1] / p[2];
+ residuals[0] = xp - T(observed_u);
+ residuals[1] = yp - T(observed_v);
+ return true;
+ }
+
+ static ceres::CostFunction* Create(const double observed_x,
+ const double observed_y)
+ {
+ return (new ceres::AutoDiffCostFunction<
+ ReprojectionErrorH, 2, 4, 3, 3, 3>(
+ new ReprojectionErrorH(observed_x,observed_y)));
+ }
+
+ double observed_u;
+ double observed_v;
+};
+
+
class GlobalSFM
{
public:
@@ -61,6 +95,10 @@ public:
const Matrix3d relative_R, const Vector3d relative_T,
vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points);
+ bool constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
+ const Matrix3d relative_R, const Vector3d relative_T, const Vector3d n,
+ vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points);
+
private:
bool solveFrameByPnP(Matrix3d &R_initial, Vector3d &P_initial, int i, vector<SFMFeature> &sfm_f);
@@ -71,4 +109,4 @@ private:
vector<SFMFeature> &sfm_f);
int feature_num;
-};
\ No newline at end of file
+};
diff --git a/vins_estimator/src/initial/solve_5pts.cpp b/vins_estimator/src/initial/solve_5pts.cpp
index 50999c3..bdc87a3 100644
--- a/vins_estimator/src/initial/solve_5pts.cpp
+++ b/vins_estimator/src/initial/solve_5pts.cpp
@@ -228,7 +228,7 @@ bool MotionEstimator::solveRelativeRT(const vector<pair<Vector3d, Vector3d>> &co
}
-bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &Rotation, Vector3d &Translation)
+bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &Rotation, Vector3d &Translation, Vector3d &n)
{
if (corres.size() >= 15)
{
@@ -244,21 +244,26 @@ bool MotionEstimator::solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &c
cv::Mat K = (cv::Mat_<double>(3, 3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
//cv::Mat K = (cv::Mat_<double>(3,3) << 665, 0, 511, 0, 665, 383, 0, 0, 1);
- Eigen::Matrix4d Tr = decomposeH(H, K, R_imu, TrIC);
- Rotation = Tr.block(0,0,3,3);
- Translation = Tr.block(0,3,3,1);
+ Eigen::Matrix4d est_Tr;
+ Eigen::Vector3d est_n;
+ decomposeH(H, K, R_imu, TrIC, est_Tr, est_n);
+ Rotation = est_Tr.block(0,0,3,3);
+ Translation = est_Tr.block(0,3,3,1);
+ n = est_n;
return true;
}
return false;
}
-Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC)
+void MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix4d &est_Tr, Vector3d &est_n)
{
vector<cv::Mat> cv_Rs, cv_ts, cv_ns;
int n_sols = cv::decomposeHomographyMat(H, K, cv_Rs, cv_ts, cv_ns);
vector<Matrix4d> positive_depth_transforms;
+ vector<Vector3d> positive_depth_normals;
+
if(n_sols > 1)
{
for(int i = 0; i < n_sols; i++)
@@ -280,6 +285,7 @@ Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const M
cv::cv2eigen(cv_ns[i], n);
if(n.dot(e3) > 0)
positive_depth_transforms.push_back(Tr);
+ positive_depth_normals.push_back(n);
}
vector<double> rot_diff;
@@ -292,8 +298,8 @@ Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const M
}
int min_index = std::min_element(rot_diff.begin(), rot_diff.end()) - rot_diff.begin();
- Matrix4d Tr = positive_depth_transforms[min_index];
- return Tr;
+ est_Tr = positive_depth_transforms[min_index];
+ est_n = positive_depth_normals[min_index];
}
else
@@ -307,8 +313,11 @@ Matrix4d MotionEstimator::decomposeH(const cv::Mat &H, const cv::Mat &K, const M
cv::cv2eigen(cv_ts[0], t);
Tr.block(0,3,3,1) = t;
+ Vector3d n;
+ cv::cv2eigen(cv_ns[0], n);
+
//Tr = TrIC * Tr * TrIC.inverse();
- Tr = Tr.inverse().eval();
- return Tr;
+ est_Tr = Tr.inverse().eval();
+ est_n = n;
}
}
diff --git a/vins_estimator/src/initial/solve_5pts.h b/vins_estimator/src/initial/solve_5pts.h
index 9fb118e..f090370 100644
--- a/vins_estimator/src/initial/solve_5pts.h
+++ b/vins_estimator/src/initial/solve_5pts.h
@@ -15,8 +15,8 @@ class MotionEstimator
public:
bool solveRelativeRT(const vector<pair<Vector3d, Vector3d>> &corres, Matrix3d &R, Vector3d &T);
- bool solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &R, Vector3d &T);
- Matrix4d decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC);
+ bool solveRelativeHRT(const vector<pair<Vector3d, Vector3d>> &corres, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix3d &R, Vector3d &T, Vector3d &n);
+ void decomposeH(const cv::Mat &H, const cv::Mat &K, const Matrix3d &R_imu, const Matrix4d &TrIC, Matrix4d &est_Tr, Vector3d &est_n);
private:
double testTriangulation(const vector<cv::Point2f> &l,
--
2.17.1
From fb6f3cf6cf15d5119c170b55e86ca5784773f970 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Wed, 23 Sep 2020 08:12:13 +0530
Subject: [PATCH 05/42] Fix parameter bugs
---
vins_estimator/src/initial/initial_sfm.cpp | 15 +++++++++++----
vins_estimator/src/initial/initial_sfm.h | 1 +
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/vins_estimator/src/initial/initial_sfm.cpp b/vins_estimator/src/initial/initial_sfm.cpp
index c7b1661..05917a0 100644
--- a/vins_estimator/src/initial/initial_sfm.cpp
+++ b/vins_estimator/src/initial/initial_sfm.cpp
@@ -104,6 +104,9 @@ void GlobalSFM::triangulateTwoFrames(int frame0, Eigen::Matrix<double, 3, 4> &Po
sfm_f[j].position[0] = point_3d(0);
sfm_f[j].position[1] = point_3d(1);
sfm_f[j].position[2] = point_3d(2);
+ sfm_f[j].image[0] = point1[0];
+ sfm_f[j].image[1] = point1[1];
+ sfm_f[j].image[2] = 1;
//cout << "trangulated : " << frame1 << " 3d point : " << j << " " << point_3d.transpose() << endl;
}
}
@@ -212,6 +215,9 @@ bool GlobalSFM::construct(int frame_num, Quaterniond* q, Vector3d* T, int l,
sfm_f[j].position[0] = point_3d(0);
sfm_f[j].position[1] = point_3d(1);
sfm_f[j].position[2] = point_3d(2);
+ sfm_f[j].image[0] = point1[0];
+ sfm_f[j].image[1] = point1[1];
+ sfm_f[j].image[2] = 1;
//cout << "trangulated : " << frame_0 << " " << frame_1 << " 3d point : " << j << " " << point_3d.transpose() << endl;
}
}
@@ -410,6 +416,9 @@ bool GlobalSFM::constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
sfm_f[j].position[0] = point_3d(0);
sfm_f[j].position[1] = point_3d(1);
sfm_f[j].position[2] = point_3d(2);
+ sfm_f[j].image[0] = point1[0];
+ sfm_f[j].image[1] = point1[1];
+ sfm_f[j].image[2] = 1;
//cout << "trangulated : " << frame_0 << " " << frame_1 << " 3d point : " << j << " " << point_3d.transpose() << endl;
}
}
@@ -471,16 +480,14 @@ bool GlobalSFM::constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
sfm_f[i].observation[j].second.y());
problem.AddResidualBlock(b_cost_function, NULL, c_rotation[l], c_translation[l],
- sfm_f[i].position);
+ sfm_f[i].position);
ceres::CostFunction* h_cost_function = ReprojectionErrorH::Create(
sfm_f[i].observation[j].second.x(),
sfm_f[i].observation[j].second.y());
- problem.AddResidualBlock(h_cost_function, NULL, c_rotation[l], c_translation[l],c_normal,
- sfm_f[i].position);
+ problem.AddResidualBlock(h_cost_function, NULL, c_rotation[l], c_translation[l], c_normal, sfm_f[i].image);
}
-
}
ceres::Solver::Options options;
options.linear_solver_type = ceres::DENSE_SCHUR;
diff --git a/vins_estimator/src/initial/initial_sfm.h b/vins_estimator/src/initial/initial_sfm.h
index a1e6854..7780732 100644
--- a/vins_estimator/src/initial/initial_sfm.h
+++ b/vins_estimator/src/initial/initial_sfm.h
@@ -19,6 +19,7 @@ struct SFMFeature
int id;
vector<pair<int,Vector2d>> observation;
double position[3];
+ double image[3]; // u v 1
double depth;
};
--
2.17.1
From d33f9314e26d538f07fdb97cc6278b5a4f449b41 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Thu, 1 Oct 2020 11:11:06 +0530
Subject: [PATCH 06/42] Add homography const functor into estimator
---
vins_estimator/src/estimator.cpp | 5 +-
vins_estimator/src/estimator.h | 2 +
vins_estimator/src/factor/homography_factor.h | 47 +++++++++++++++++++
vins_estimator/src/initial/initial_sfm.cpp | 7 ++-
vins_estimator/src/initial/initial_sfm.h | 4 +-
5 files changed, 61 insertions(+), 4 deletions(-)
create mode 100644 vins_estimator/src/factor/homography_factor.h
diff --git a/vins_estimator/src/estimator.cpp b/vins_estimator/src/estimator.cpp
index c561fd6..97a3821 100644
--- a/vins_estimator/src/estimator.cpp
+++ b/vins_estimator/src/estimator.cpp
@@ -435,7 +435,7 @@ bool Estimator::visualInitialAlign()
Vs[i] = rot_diff * Vs[i];
}
ROS_DEBUG_STREAM("g0 " << g.transpose());
- ROS_DEBUG_STREAM("my R0 " << Utility::R2ypr(Rs[0]).transpose());
+ ROS_DEBUG_STREAM("my R0 " << Utility::R2ypr(Rs[0]).transpose());
return true;
}
@@ -800,6 +800,9 @@ void Estimator::optimization()
{
ProjectionFactor *f = new ProjectionFactor(pts_i, pts_j);
problem.AddResidualBlock(f, loss_function, para_Pose[imu_i], para_Pose[imu_j], para_Ex_Pose[0], para_Feature[feature_index]);
+
+ ceres::CostFunction *h_cost_function = HomographyFactor::Create(pts_i, pts_j);
+ problem.AddResidualBlock(h_cost_function, loss_function, para_Pose[imu_i], para_Pose[imu_j], para_N, para_Ex_Pose[0]);
}
f_m_cnt++;
}
diff --git a/vins_estimator/src/estimator.h b/vins_estimator/src/estimator.h
index 9b2a731..f3feedf 100644
--- a/vins_estimator/src/estimator.h
+++ b/vins_estimator/src/estimator.h
@@ -17,6 +17,7 @@
#include "factor/projection_factor.h"
#include "factor/projection_td_factor.h"
#include "factor/marginalization_factor.h"
+#include "factor/homography_factor.h"
#include <unordered_map>
#include <queue>
@@ -114,6 +115,7 @@ class Estimator
double para_Retrive_Pose[SIZE_POSE];
double para_Td[1][1];
double para_Tr[1][1];
+ double para_N[3];
int loop_window_index;
diff --git a/vins_estimator/src/factor/homography_factor.h b/vins_estimator/src/factor/homography_factor.h
new file mode 100644
index 0000000..86b03ff
--- /dev/null
+++ b/vins_estimator/src/factor/homography_factor.h
@@ -0,0 +1,47 @@
+#pragma once
+#include <ceres/ceres.h>
+#include <eigen3/Eigen/Dense>
+
+struct HomographyFactor
+{
+ HomographyFactor(const Eigen::Vector3d &_pts_i, const Eigen::Vector3d &_pts_j) : pts_i(_pts_i), pts_j(_pts_j) {}
+
+ template <typename T>
+ bool operator()(const T* const pose_i, const T* const pose_j, const T* const para_n, const T* const ex_pose,
+ T* residuals) const
+ {
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> pi(pose_i);
+ Eigen::Quaternion<T> qi;
+ qi.coeffs() << pose_i[3], pose_i[4], pose_i[5], pose_i[6];
+
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> pj(pose_j);
+ Eigen::Quaternion<T> qj;
+ qj.coeffs() << pose_j[3], pose_j[4], pose_j[5], pose_j[6];
+
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> tic(ex_pose);
+ Eigen::Quaternion<T> qic;
+ qic.coeffs() << ex_pose[3], ex_pose[4], ex_pose[5], ex_pose[6];
+
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> n(para_n);
+
+ Eigen::Quaternion<T> qji = qj.inverse() * qi;
+ Eigen::Matrix<T, 3, 1> tji = qj.inverse().toRotationMatrix() * (pi - pj);
+ Eigen::Matrix<T, 3, 1> pts_imu_i = qic * pts_i.cast<T>() + tic;
+ Eigen::Matrix<T, 3, 1> pts_imu_j = qji * pts_imu_i + tji * n.transpose() * pts_imu_i;
+ Eigen::Matrix<T, 3, 1> pts_cam_j = qic.inverse() * (pts_imu_j - tic);
+
+ pts_cam_j = (pts_cam_j / pts_cam_j[2]);
+ residuals[0] = pts_cam_j[0] - pts_j[0];
+ residuals[1] = pts_cam_j[1] - pts_j[1];
+
+ return true;
+ }
+
+ static ceres::CostFunction* Create(const Eigen::Vector3d &_pts_i, const Eigen::Vector3d &_pts_j)
+ {
+ return (new ceres::AutoDiffCostFunction<HomographyFactor, 2, 7, 7, 3, 7>
+ (new HomographyFactor(_pts_i, _pts_j)));
+ }
+
+ Eigen::Vector3d pts_i, pts_j;
+};
diff --git a/vins_estimator/src/initial/initial_sfm.cpp b/vins_estimator/src/initial/initial_sfm.cpp
index 05917a0..76a4f88 100644
--- a/vins_estimator/src/initial/initial_sfm.cpp
+++ b/vins_estimator/src/initial/initial_sfm.cpp
@@ -319,7 +319,7 @@ bool GlobalSFM::construct(int frame_num, Quaterniond* q, Vector3d* T, int l,
bool GlobalSFM::constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
- const Matrix3d relative_R, const Vector3d relative_T, const Vector3d n,
+ const Matrix3d relative_R, const Vector3d relative_T, Vector3d &n,
vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points)
{
feature_num = sfm_f.size();
@@ -525,6 +525,11 @@ bool GlobalSFM::constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
if(sfm_f[i].state)
sfm_tracked_points[sfm_f[i].id] = Vector3d(sfm_f[i].position[0], sfm_f[i].position[1], sfm_f[i].position[2]);
}
+
+ n[0] = c_normal[0];
+ n[1] = c_normal[1];
+ n[2] = c_normal[2];
+
return true;
}
diff --git a/vins_estimator/src/initial/initial_sfm.h b/vins_estimator/src/initial/initial_sfm.h
index 7780732..e79dcea 100644
--- a/vins_estimator/src/initial/initial_sfm.h
+++ b/vins_estimator/src/initial/initial_sfm.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <ceres/ceres.h>
#include <ceres/rotation.h>
#include <eigen3/Eigen/Dense>
@@ -97,7 +97,7 @@ public:
vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points);
bool constructH(int frame_num, Quaterniond* q, Vector3d* T, int l,
- const Matrix3d relative_R, const Vector3d relative_T, const Vector3d n,
+ const Matrix3d relative_R, const Vector3d relative_T, Vector3d &n,
vector<SFMFeature> &sfm_f, map<int, Vector3d> &sfm_tracked_points);
private:
--
2.17.1
From d3d1faeaa37f6b413622e6b3373c80cffc4182f7 Mon Sep 17 00:00:00 2001
From: Karnik Ram <[email protected]>
Date: Thu, 1 Oct 2020 11:57:44 +0530
Subject: [PATCH 07/42] Add code for transforming normal vector
---
vins_estimator/src/estimator.cpp | 3 +++
vins_estimator/src/factor/homography_factor.h | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/vins_estimator/src/estimator.cpp b/vins_estimator/src/estimator.cpp