File: pyopengv.cpp

package info (click to toggle)
opengv 1.0%2B1git91f4b1-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,480 kB
  • sloc: cpp: 45,813; python: 152; makefile: 17; xml: 13; sh: 4
file content (741 lines) | stat: -rw-r--r-- 20,759 bytes parent folder | download | duplicates (2)
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
#include <iostream>
#include <vector>
#include <opengv/absolute_pose/AbsoluteAdapterBase.hpp>
#include <opengv/absolute_pose/methods.hpp>
#include <opengv/relative_pose/RelativeAdapterBase.hpp>
#include <opengv/relative_pose/methods.hpp>
#include <opengv/sac/Ransac.hpp>
#include <opengv/sac/Lmeds.hpp>
#include <opengv/sac_problems/absolute_pose/AbsolutePoseSacProblem.hpp>
#include <opengv/sac_problems/relative_pose/CentralRelativePoseSacProblem.hpp>
#include <opengv/sac_problems/relative_pose/RotationOnlySacProblem.hpp>
#include <opengv/triangulation/methods.hpp>

#include "types.hpp"


namespace pyopengv {


opengv::bearingVector_t bearingVectorFromArray(
    const pyarray_d &array,
    size_t index )
{
  opengv::bearingVector_t v;
  v[0] = *array.data(index, 0);
  v[1] = *array.data(index, 1);
  v[2] = *array.data(index, 2);
  return v;
}

opengv::point_t pointFromArray(
    const pyarray_d &array,
    size_t index )
{
  opengv::point_t p;
  p[0] = *array.data(index, 0);
  p[1] = *array.data(index, 1);
  p[2] = *array.data(index, 2);
  return p;
}

py::object arrayFromPoints( const opengv::points_t &points )
{
  std::vector<double> data(points.size() * 3);
  for (size_t i = 0; i < points.size(); ++i) {
    data[3 * i + 0] = points[i][0];
    data[3 * i + 1] = points[i][1];
    data[3 * i + 2] = points[i][2];
  }
  return py_array_from_data(&data[0], points.size(), 3);
}

py::object arrayFromTranslation( const opengv::translation_t &t )
{
  return py_array_from_data(t.data(), 3);
}

py::object arrayFromRotation( const opengv::rotation_t &R )
{
  Eigen::Matrix<double, 3, 3, Eigen::RowMajor> R_row_major = R;
  return py_array_from_data(R_row_major.data(), 3, 3);
}

py::list listFromRotations( const opengv::rotations_t &Rs )
{
  py::list retn;
  for (size_t i = 0; i < Rs.size(); ++i) {
    retn.append(arrayFromRotation(Rs[i]));
  }
  return retn;
}

py::object arrayFromEssential( const opengv::essential_t &E )
{
  Eigen::Matrix<double, 3, 3, Eigen::RowMajor> E_row_major = E;
  return py_array_from_data(E_row_major.data(), 3, 3);
}

py::list listFromEssentials( const opengv::essentials_t &Es )
{
  py::list retn;
  for (size_t i = 0; i < Es.size(); ++i) {
    retn.append(arrayFromEssential(Es[i]));
  }
  return retn;
}

py::object arrayFromTransformation( const opengv::transformation_t &t )
{
  Eigen::Matrix<double, 3, 4, Eigen::RowMajor> t_row_major = t;
  return py_array_from_data(t_row_major.data(), 3, 4);
}

py::list listFromTransformations( const opengv::transformations_t &t )
{
  py::list retn;
  for (size_t i = 0; i < t.size(); ++i) {
    retn.append(arrayFromTransformation(t[i]));
  }
  return retn;
}

std::vector<int> getNindices( int n )
{
  std::vector<int> indices;
  for(int i = 0; i < n; i++)
    indices.push_back(i);
  return indices;
}


namespace absolute_pose {

class CentralAbsoluteAdapter : public opengv::absolute_pose::AbsoluteAdapterBase
{
protected:
  using AbsoluteAdapterBase::_t;
  using AbsoluteAdapterBase::_R;

public:
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW

  CentralAbsoluteAdapter(
      pyarray_d &bearingVectors,
      pyarray_d &points )
    : _bearingVectors(bearingVectors)
    , _points(points)
  {}

  CentralAbsoluteAdapter(
      pyarray_d &bearingVectors,
      pyarray_d &points,
      pyarray_d &R )
    : _bearingVectors(bearingVectors)
    , _points(points)
  {
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        _R(i, j) = *R.data(i, j);
      }
    }
  }

  CentralAbsoluteAdapter(
      pyarray_d &bearingVectors,
      pyarray_d &points,
      pyarray_d &t,
      pyarray_d &R )
    : _bearingVectors(bearingVectors)
    , _points(points)
  {
    for (int i = 0; i < 3; ++i) {
      _t(i) = *t.data(i);
    }
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        _R(i, j) = *R.data(i, j);
      }
    }
  }

  virtual ~CentralAbsoluteAdapter() {}

  //Access of correspondences

  virtual opengv::bearingVector_t getBearingVector( size_t index ) const {
    return bearingVectorFromArray(_bearingVectors, index);
  }

  virtual double getWeight( size_t index ) const {
    return 1.0;
  }

  virtual opengv::translation_t getCamOffset( size_t index ) const {
    return Eigen::Vector3d::Zero();
  }

  virtual opengv::rotation_t getCamRotation( size_t index ) const {
    return opengv::rotation_t::Identity();
  }

  virtual opengv::point_t getPoint( size_t index ) const {
    return pointFromArray(_points, index);
  }

  virtual size_t getNumberCorrespondences() const {
    return _bearingVectors.shape(0);
  }

protected:
  pyarray_d _bearingVectors;
  pyarray_d _points;
};



py::object p2p( pyarray_d &v, pyarray_d &p, pyarray_d &R )
{
  CentralAbsoluteAdapter adapter(v, p, R);
  return arrayFromTranslation(
    opengv::absolute_pose::p2p(adapter, 0, 1));
}

py::object p3p_kneip( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return listFromTransformations(
    opengv::absolute_pose::p3p_kneip(adapter, 0, 1, 2));
}

py::object p3p_gao( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return listFromTransformations(
    opengv::absolute_pose::p3p_gao(adapter, 0, 1, 2));
}

py::object gp3p( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return listFromTransformations(
    opengv::absolute_pose::gp3p(adapter, 0, 1, 2));
}

py::object epnp( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return arrayFromTransformation(
    opengv::absolute_pose::epnp(adapter));
}

py::object gpnp( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return arrayFromTransformation(
    opengv::absolute_pose::gpnp(adapter));
}

py::object upnp( pyarray_d &v, pyarray_d &p )
{
  CentralAbsoluteAdapter adapter(v, p);
  return listFromTransformations(
    opengv::absolute_pose::upnp(adapter));
}

py::object optimize_nonlinear( pyarray_d &v,
                               pyarray_d &p,
                               pyarray_d &t,
                               pyarray_d &R )
{
  CentralAbsoluteAdapter adapter(v, p, t, R);
  return arrayFromTransformation(
    opengv::absolute_pose::optimize_nonlinear(adapter));
}

py::object ransac(
    pyarray_d &v,
    pyarray_d &p,
    std::string algo_name,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::absolute_pose;

  CentralAbsoluteAdapter adapter(v, p);

  // Create a ransac problem
  AbsolutePoseSacProblem::algorithm_t algorithm = AbsolutePoseSacProblem::KNEIP;
  if (algo_name == "TWOPT") algorithm = AbsolutePoseSacProblem::TWOPT;
  else if (algo_name == "KNEIP") algorithm = AbsolutePoseSacProblem::KNEIP;
  else if (algo_name == "GAO") algorithm = AbsolutePoseSacProblem::GAO;
  else if (algo_name == "EPNP") algorithm = AbsolutePoseSacProblem::EPNP;
  else if (algo_name == "GP3P") algorithm = AbsolutePoseSacProblem::GP3P;

  std::shared_ptr<AbsolutePoseSacProblem>
      absposeproblem_ptr(
        new AbsolutePoseSacProblem(adapter, algorithm));

  // Create a ransac solver for the problem
  opengv::sac::Ransac<AbsolutePoseSacProblem> ransac;

  ransac.sac_model_ = absposeproblem_ptr;
  ransac.threshold_ = threshold;
  ransac.max_iterations_ = max_iterations;
  ransac.probability_ = probability;

  // Solve
  ransac.computeModel();
  return arrayFromTransformation(ransac.model_coefficients_);
}

py::object lmeds(
    pyarray_d &v,
    pyarray_d &p,
    std::string algo_name,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::absolute_pose;

  CentralAbsoluteAdapter adapter(v, p);

  // Create a lmeds problem
  AbsolutePoseSacProblem::algorithm_t algorithm = AbsolutePoseSacProblem::KNEIP;
  if (algo_name == "TWOPT") algorithm = AbsolutePoseSacProblem::TWOPT;
  else if (algo_name == "KNEIP") algorithm = AbsolutePoseSacProblem::KNEIP;
  else if (algo_name == "GAO") algorithm = AbsolutePoseSacProblem::GAO;
  else if (algo_name == "EPNP") algorithm = AbsolutePoseSacProblem::EPNP;
  else if (algo_name == "GP3P") algorithm = AbsolutePoseSacProblem::GP3P;

  std::shared_ptr<AbsolutePoseSacProblem>
      absposeproblem_ptr(
        new AbsolutePoseSacProblem(adapter, algorithm));

  // Create a ransac solver for the problem
  opengv::sac::Lmeds<AbsolutePoseSacProblem> lmeds;

  lmeds.sac_model_ = absposeproblem_ptr;
  lmeds.threshold_ = threshold;
  lmeds.max_iterations_ = max_iterations;
  lmeds.probability_ = probability;

  // Solve
  lmeds.computeModel();
  return arrayFromTransformation(lmeds.model_coefficients_);
}

} // namespace absolute_pose


namespace relative_pose
{

class CentralRelativeAdapter : public opengv::relative_pose::RelativeAdapterBase
{
protected:
  using RelativeAdapterBase::_t12;
  using RelativeAdapterBase::_R12;

public:
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW

  CentralRelativeAdapter(
      pyarray_d &bearingVectors1,
      pyarray_d &bearingVectors2 )
    : _bearingVectors1(bearingVectors1)
    , _bearingVectors2(bearingVectors2)
  {}

  CentralRelativeAdapter(
      pyarray_d &bearingVectors1,
      pyarray_d &bearingVectors2,
      pyarray_d &R12 )
    : _bearingVectors1(bearingVectors1)
    , _bearingVectors2(bearingVectors2)
  {
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        _R12(i, j) = *R12.data(i, j);
      }
    }
  }

  CentralRelativeAdapter(
      pyarray_d &bearingVectors1,
      pyarray_d &bearingVectors2,
      pyarray_d &t12,
      pyarray_d &R12 )
    : _bearingVectors1(bearingVectors1)
    , _bearingVectors2(bearingVectors2)
  {
    for (int i = 0; i < 3; ++i) {
      _t12(i) = *t12.data(i);
    }
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        _R12(i, j) = *R12.data(i, j);
      }
    }
  }

  virtual ~CentralRelativeAdapter() {}

  virtual opengv::bearingVector_t getBearingVector1( size_t index ) const {
    return bearingVectorFromArray(_bearingVectors1, index);
  }

  virtual opengv::bearingVector_t getBearingVector2( size_t index ) const {
    return bearingVectorFromArray(_bearingVectors2, index);
  }

  virtual double getWeight( size_t index ) const {
    return 1.0;
  }

  virtual opengv::translation_t getCamOffset1( size_t index ) const {
    return Eigen::Vector3d::Zero();
  }

  virtual opengv::rotation_t getCamRotation1( size_t index ) const {
    return opengv::rotation_t::Identity();
  }

  virtual opengv::translation_t getCamOffset2( size_t index ) const {
    return Eigen::Vector3d::Zero();
  }

  virtual opengv::rotation_t getCamRotation2( size_t index ) const {
    return opengv::rotation_t::Identity();
  }

  virtual size_t getNumberCorrespondences() const {
    return _bearingVectors1.shape(0);
  }

protected:
  pyarray_d _bearingVectors1;
  pyarray_d _bearingVectors2;
};


py::object twopt( pyarray_d &b1, pyarray_d &b2, pyarray_d &R )
{
  CentralRelativeAdapter adapter(b1, b2, R);
  return arrayFromTranslation(
    opengv::relative_pose::twopt(adapter, true, 0, 1));
}

py::object twopt_rotationOnly( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return arrayFromRotation(
    opengv::relative_pose::twopt_rotationOnly(adapter, 0, 1));
}

py::object rotationOnly( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return arrayFromRotation(
    opengv::relative_pose::rotationOnly(adapter));
}

py::object fivept_nister( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return listFromEssentials(
    opengv::relative_pose::fivept_nister(adapter));
}

py::object fivept_kneip( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return listFromRotations(
    opengv::relative_pose::fivept_kneip(adapter, getNindices(5)));
}

py::object sevenpt( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return listFromEssentials(
    opengv::relative_pose::sevenpt(adapter));
}

py::object eightpt( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return arrayFromEssential(
    opengv::relative_pose::eightpt(adapter));
}

py::object eigensolver( pyarray_d &b1, pyarray_d &b2, pyarray_d &R )
{
  CentralRelativeAdapter adapter(b1, b2, R);
  return arrayFromRotation(
    opengv::relative_pose::eigensolver(adapter));
}

py::object sixpt( pyarray_d &b1, pyarray_d &b2 )
{
  CentralRelativeAdapter adapter(b1, b2);
  return listFromRotations(
    opengv::relative_pose::sixpt(adapter));
}

py::object optimize_nonlinear( pyarray_d &b1,
                               pyarray_d &b2,
                               pyarray_d &t12,
                               pyarray_d &R12 )
{
  CentralRelativeAdapter adapter(b1, b2, t12, R12);
  return arrayFromTransformation(
    opengv::relative_pose::optimize_nonlinear(adapter));
}

py::object ransac(
    pyarray_d &b1,
    pyarray_d &b2,
    std::string algo_name,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::relative_pose;

  CentralRelativeAdapter adapter(b1, b2);

  // Create a ransac problem
  CentralRelativePoseSacProblem::algorithm_t algorithm = CentralRelativePoseSacProblem::NISTER;
  if (algo_name == "STEWENIUS") algorithm = CentralRelativePoseSacProblem::STEWENIUS;
  else if (algo_name == "NISTER") algorithm = CentralRelativePoseSacProblem::NISTER;
  else if (algo_name == "SEVENPT") algorithm = CentralRelativePoseSacProblem::SEVENPT;
  else if (algo_name == "EIGHTPT") algorithm = CentralRelativePoseSacProblem::EIGHTPT;

  std::shared_ptr<CentralRelativePoseSacProblem>
      relposeproblem_ptr(
        new CentralRelativePoseSacProblem(adapter, algorithm));

  // Create a ransac solver for the problem
  opengv::sac::Ransac<CentralRelativePoseSacProblem> ransac;

  ransac.sac_model_ = relposeproblem_ptr;
  ransac.threshold_ = threshold;
  ransac.max_iterations_ = max_iterations;
  ransac.probability_ = probability;

  // Solve
  ransac.computeModel();
  return arrayFromTransformation(ransac.model_coefficients_);
}

py::object lmeds(
    pyarray_d &b1,
    pyarray_d &b2,
    std::string algo_name,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::relative_pose;

  CentralRelativeAdapter adapter(b1, b2);

  // Create a lmeds problem
  CentralRelativePoseSacProblem::algorithm_t algorithm = CentralRelativePoseSacProblem::NISTER;
  if (algo_name == "STEWENIUS") algorithm = CentralRelativePoseSacProblem::STEWENIUS;
  else if (algo_name == "NISTER") algorithm = CentralRelativePoseSacProblem::NISTER;
  else if (algo_name == "SEVENPT") algorithm = CentralRelativePoseSacProblem::SEVENPT;
  else if (algo_name == "EIGHTPT") algorithm = CentralRelativePoseSacProblem::EIGHTPT;

  std::shared_ptr<CentralRelativePoseSacProblem>
      relposeproblem_ptr(
        new CentralRelativePoseSacProblem(adapter, algorithm));

  // Create a lmeds solver for the problem
  opengv::sac::Lmeds<CentralRelativePoseSacProblem> lmeds;

  lmeds.sac_model_ = relposeproblem_ptr;
  lmeds.threshold_ = threshold;
  lmeds.max_iterations_ = max_iterations;
  lmeds.probability_ = probability;

  // Solve
  lmeds.computeModel();
  return arrayFromTransformation(lmeds.model_coefficients_);
}

py::object ransac_rotationOnly(
    pyarray_d &b1,
    pyarray_d &b2,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::relative_pose;

  CentralRelativeAdapter adapter(b1, b2);

  std::shared_ptr<RotationOnlySacProblem>
      relposeproblem_ptr(
        new RotationOnlySacProblem(adapter));

  // Create a ransac solver for the problem
  opengv::sac::Ransac<RotationOnlySacProblem> ransac;

  ransac.sac_model_ = relposeproblem_ptr;
  ransac.threshold_ = threshold;
  ransac.max_iterations_ = max_iterations;
  ransac.probability_ = probability;

  // Solve
  ransac.computeModel();
  return arrayFromRotation(ransac.model_coefficients_);
}

py::object lmeds_rotationOnly(
    pyarray_d &b1,
    pyarray_d &b2,
    double threshold,
    int max_iterations,
    double probability )
{
  using namespace opengv::sac_problems::relative_pose;

  CentralRelativeAdapter adapter(b1, b2);

  std::shared_ptr<RotationOnlySacProblem>
      relposeproblem_ptr(
        new RotationOnlySacProblem(adapter));

  // Create a lmeds solver for the problem
  opengv::sac::Lmeds<RotationOnlySacProblem> lmeds;

  lmeds.sac_model_ = relposeproblem_ptr;
  lmeds.threshold_ = threshold;
  lmeds.max_iterations_ = max_iterations;
  lmeds.probability_ = probability;

  // Solve
  lmeds.computeModel();
  return arrayFromRotation(lmeds.model_coefficients_);
}

} // namespace relative_pose

namespace triangulation
{

py::object triangulate( pyarray_d &b1,
                        pyarray_d &b2,
                        pyarray_d &t12,
                        pyarray_d &R12 )
{
  pyopengv::relative_pose::CentralRelativeAdapter adapter(b1, b2, t12, R12);

  opengv::points_t points;
  for (size_t i = 0; i < adapter.getNumberCorrespondences(); ++i)
  {
    opengv::point_t p = opengv::triangulation::triangulate(adapter, i);
    points.push_back(p);
  }
  return arrayFromPoints(points);
}

py::object triangulate2( pyarray_d &b1,
                         pyarray_d &b2,
                         pyarray_d &t12,
                         pyarray_d &R12 )
{
  pyopengv::relative_pose::CentralRelativeAdapter adapter(b1, b2, t12, R12);

  opengv::points_t points;
  for (size_t i = 0; i < adapter.getNumberCorrespondences(); ++i)
  {
    opengv::point_t p = opengv::triangulation::triangulate2(adapter, i);
    points.push_back(p);
  }
  return arrayFromPoints(points);
}


} // namespace triangulation

} // namespace pyopengv


PYBIND11_MODULE(pyopengv, m) {
  namespace py = pybind11;

  m.def("absolute_pose_p2p", pyopengv::absolute_pose::p2p);
  m.def("absolute_pose_p3p_kneip", pyopengv::absolute_pose::p3p_kneip);
  m.def("absolute_pose_p3p_gao", pyopengv::absolute_pose::p3p_gao);
  m.def("absolute_pose_gp3p", pyopengv::absolute_pose::gp3p);
  m.def("absolute_pose_epnp", pyopengv::absolute_pose::epnp);
  m.def("absolute_pose_gpnp", pyopengv::absolute_pose::gpnp);
  m.def("absolute_pose_upnp", pyopengv::absolute_pose::upnp);
  m.def("absolute_pose_optimize_nonlinear", pyopengv::absolute_pose::optimize_nonlinear);
  m.def("absolute_pose_ransac", pyopengv::absolute_pose::ransac,
        py::arg("v"),
        py::arg("p"),
        py::arg("algo_name"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );
  m.def("absolute_pose_lmeds", pyopengv::absolute_pose::lmeds,
        py::arg("v"),
        py::arg("p"),
        py::arg("algo_name"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );

  m.def("relative_pose_twopt", pyopengv::relative_pose::twopt);
  m.def("relative_pose_twopt_rotation_only", pyopengv::relative_pose::twopt_rotationOnly);
  m.def("relative_pose_rotation_only", pyopengv::relative_pose::rotationOnly);
  m.def("relative_pose_fivept_nister", pyopengv::relative_pose::fivept_nister);
  m.def("relative_pose_fivept_kneip", pyopengv::relative_pose::fivept_kneip);
  m.def("relative_pose_sevenpt", pyopengv::relative_pose::sevenpt);
  m.def("relative_pose_eightpt", pyopengv::relative_pose::eightpt);
  m.def("relative_pose_eigensolver", pyopengv::relative_pose::eigensolver);
  m.def("relative_pose_sixpt", pyopengv::relative_pose::sixpt);
  m.def("relative_pose_optimize_nonlinear", pyopengv::relative_pose::optimize_nonlinear);
  m.def("relative_pose_ransac", pyopengv::relative_pose::ransac,
        py::arg("b1"),
        py::arg("b2"),
        py::arg("algo_name"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );
  m.def("relative_pose_lmeds", pyopengv::relative_pose::lmeds,
        py::arg("b1"),
        py::arg("b2"),
        py::arg("algo_name"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );
  m.def("relative_pose_ransac_rotation_only", pyopengv::relative_pose::ransac_rotationOnly,
        py::arg("b1"),
        py::arg("b2"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );
  m.def("relative_pose_lmeds_rotation_only", pyopengv::relative_pose::lmeds_rotationOnly,
        py::arg("b1"),
        py::arg("b2"),
        py::arg("threshold"),
        py::arg("iterations") = 1000,
        py::arg("probability") = 0.99
  );



  m.def("triangulation_triangulate", pyopengv::triangulation::triangulate);
  m.def("triangulation_triangulate2", pyopengv::triangulation::triangulate2);
}