Skip to content

Commit e7a381f

Browse files
authored
Merge pull request #1788 from alicevision/dev/swig
Add SWIG binding of camera shared pointers
2 parents 7d73bc0 + 65f2f36 commit e7a381f

29 files changed

+258
-107
lines changed

pyTests/camera/test_equidistant.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pyalicevision import camera as av
8+
from pyalicevision import numeric as avnum
89

910
##################
1011
### List of functions:
@@ -163,12 +164,10 @@ def test_equidistant_default_constructor():
163164
assert intrinsic.h() == 1, "The Equidistant intrinsic's default height should be 1"
164165

165166
scale = intrinsic.getScale()
166-
# TODO: uncomment check on the scale when Vec2 is binded
167-
# assert scale[0] == 1.0 and scale[1] == 1.0
167+
assert avnum.getX(scale) == 1.0 and avnum.getY(scale) == 1.0
168168

169169
offset = intrinsic.getOffset()
170-
# TODO: uncomment check on the offset when Vec2 is binded
171-
# assert offset[0] == 0.0 and offset[1] == 0.0
170+
assert avnum.getX(offset) == 0.0 and avnum.getY(offset) == 0.0
172171

173172
assert intrinsic.sensorWidth() == 36.0
174173
assert intrinsic.sensorHeight() == 24.0
@@ -200,12 +199,10 @@ def test_equidistant_constructors():
200199
assert intrinsic1.h() == height, "The Equidistant intrinsic's height has not been correctly set"
201200

202201
scale = intrinsic1.getScale()
203-
# TODO: uncomment check on the scale when Vec2 is binded
204-
# assert scale[0] == focal and scale[1] == focal
202+
assert avnum.getX(scale) == focal and avnum.getY(scale) == focal
205203

206204
offset = intrinsic1.getOffset()
207-
# TODO: uncomment check on the offset when Vec2 is binded
208-
# assert offset[0] == offset_x and offset[1] == offset_y
205+
assert avnum.getX(offset) == offset_x and avnum.getY(offset) == offset_y
209206

210207
assert intrinsic1.sensorWidth() == 36.0
211208
assert intrinsic1.sensorHeight() == 24.0
@@ -225,12 +222,10 @@ def test_equidistant_constructors():
225222
assert intrinsic2.h() == height, "The Equidistant intrinsic's height has not been correctly set"
226223

227224
scale = intrinsic2.getScale()
228-
# TODO: uncomment check on the scale when Vec2 is binded
229-
# assert scale[0] == focal and scale[1] == focal
225+
assert avnum.getX(scale) == focal and avnum.getY(scale) == focal
230226

231227
offset = intrinsic2.getOffset()
232-
# TODO: uncomment check on the offset when Vec2 is binded
233-
# assert offset[0] == offset_x and offset[1] == offset_y
228+
assert avnum.getX(offset) == offset_x and avnum.getY(offset) == offset_y
234229

235230
assert intrinsic2.sensorWidth() == 36.0
236231
assert intrinsic2.sensorHeight() == 24.0
@@ -335,8 +330,7 @@ def test_equidistant_get_set_circle():
335330
assert intrinsic.getCircleCenterY() == center_y
336331

337332
center = intrinsic.getCircleCenter()
338-
# TODO: uncomment when Vec2 is binded
339-
# assert center[0] == center_x and center[1] == center_y
333+
assert avnum.getX(center) == center_x and avnum.getY(center) == center_y
340334

341335

342336
def test_equidistant_ratio_lock_unlock():

pyTests/camera/test_pinhole.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pyalicevision import camera as av
8+
from pyalicevision import numeric as avnum
89

910
##################
1011
### List of functions:
@@ -157,8 +158,7 @@ def test_pinhole_default_constructor():
157158
"The Pinhole intrinsic's focal length in Y should be 1.0"
158159

159160
offset = intrinsic.getOffset()
160-
# TODO: uncomment check on the offset when Vec2 is binded
161-
# assert offset[0] == 0.0 and offset[1] == 0.0
161+
assert avnum.getX(offset) == 0.0 and avnum.getY(offset) == 0.0
162162

163163
assert intrinsic.sensorWidth() == 36.0
164164
assert intrinsic.sensorHeight() == 24.0

pyTests/camera/test_undistortion_3de.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pyalicevision import camera as av
8+
from pyalicevision import numeric as avnum
89

910
##################
1011
### List of functions:
@@ -46,8 +47,7 @@ def test_undistortion_3de_constructor():
4647
undistortion = av.Undistortion3DEAnamorphic4(WIDTH, HEIGHT)
4748

4849
size = undistortion.getSize()
49-
# TODO: uncomment when Vec2 is binded
50-
# assert size[0] == WIDTH and size[1] == HEIGHT
50+
assert avnum.getX(size) == WIDTH and avnum.getY(size) == HEIGHT
5151

5252
assert undistortion.getType() == av.UNDISTORTION_3DEANAMORPHIC4
5353

@@ -117,14 +117,12 @@ def test_undistortion_3de_get_set_size():
117117
size. """
118118
undistortion = av.Undistortion3DEAnamorphic4(WIDTH, HEIGHT)
119119
size = undistortion.getSize()
120-
# TODO: uncomment when Vec2 is binded
121-
# assert size[0] == WIDTH and size[1] == HEIGHT
120+
assert avnum.getX(size) == WIDTH and avnum.getY(size) == HEIGHT
122121

123122
undistortion.setSize(HEIGHT, WIDTH)
124123
assert size != undistortion.getSize()
125124
size = undistortion.getSize()
126-
# TODO: uncomment when Vec2 is binded
127-
# assert size[0] == HEIGHT and size[1] == WIDTH
125+
assert avnum.getX(size) == HEIGHT and avnum.getY(size) == WIDTH
128126

129127

130128
@pytest.mark.skip(reason="Vec2 not binded")

pyTests/camera/test_undistortion_radial.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pyalicevision import camera as av
8+
from pyalicevision import numeric as avnum
89

910
##################
1011
### List of functions:
@@ -46,8 +47,7 @@ def test_undistortion_radial_constructor():
4647
undistortion = av.UndistortionRadialK3(WIDTH, HEIGHT)
4748

4849
size = undistortion.getSize()
49-
# TODO: uncomment when Vec2 is binded
50-
# assert size[0] == WIDTH and size[1] == HEIGHT
50+
assert avnum.getX(size) == WIDTH and avnum.getY(size) == HEIGHT
5151

5252
assert undistortion.getType() == av.UNDISTORTION_RADIALK3
5353

@@ -117,14 +117,12 @@ def test_undistortion_radial_get_set_size():
117117
size. """
118118
undistortion = av.UndistortionRadialK3(WIDTH, HEIGHT)
119119
size = undistortion.getSize()
120-
# TODO: uncomment when Vec2 is binded
121-
# assert size[0] == WIDTH and size[1] == HEIGHT
120+
assert avnum.getX(size) == WIDTH and avnum.getY(size) == HEIGHT
122121

123122
undistortion.setSize(HEIGHT, WIDTH)
124123
assert size != undistortion.getSize()
125124
size = undistortion.getSize()
126-
# TODO: uncomment when Vec2 is binded
127-
# assert size[0] == HEIGHT and size[1] == WIDTH
125+
assert avnum.getX(size) == HEIGHT and avnum.getY(size) == WIDTH
128126

129127

130128
@pytest.mark.skip(reason="Vec2 not binded")

pyTests/sfmData/test_sfmdata.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# - ImageInfos& getAncestors()
1717
# - Poses& getPoses() => DONE
1818
# - Rigs& getRigs() => DONE
19-
# - Intrinsics& getIntrinsics() => DONE / Intrinsics derived classes not fully binded
19+
# - Intrinsics& getIntrinsics() => DONE
2020
# - Landmarks& getLandmarks() => DONE
2121
# - Constraints2D& getConstraints2D() => DONE
2222
# - RotationPriors& getRotationPriors() => DONE
@@ -102,12 +102,11 @@ def test_sfmdata_get_intrinsics():
102102
assert len(intrinsics) == 0, \
103103
"The SfMData object is empty, there should not be any Intrinsic in it"
104104

105-
# TODO: Add Intrinsic object to the list once derived classes are fully binded
106-
# Create an Intrinsic object and add it to the list
107-
# intrinsic = av.IntrinsicBase()
108-
# intrinsics[INTRINSIC_ID] = intrinsic
109-
# assert len(data.getIntrinsics()) == len(intrinsics) == 1, \
110-
# "The list of Intrinsics should have been updated"
105+
#Create an Intrinsic object and add it to the list
106+
intrinsic = av.Pinhole()
107+
intrinsics[INTRINSIC_ID] = intrinsic
108+
assert len(data.getIntrinsics()) == len(intrinsics) == 1, \
109+
"The list of Intrinsics should have been updated"
111110

112111

113112
def test_sfmdata_get_landmarks():

src/aliceVision/aliceVision.i

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
%include <aliceVision/global.i>
1010
%include <aliceVision/version.hpp>
1111

12+
%import <aliceVision/numeric/numeric.i>
1213
%import <aliceVision/camera/Camera.i>
1314
%import <aliceVision/geometry/Geometry.i>
1415
%import <aliceVision/hdr/Hdr.i>
@@ -19,5 +20,12 @@
1920

2021
%{
2122
#include <aliceVision/version.hpp>
23+
24+
//For unknown reason, we need to declare cameras here too
25+
#include <aliceVision/camera/IntrinsicBase.hpp>
26+
#include <aliceVision/camera/Pinhole.hpp>
27+
#include <aliceVision/camera/Equidistant.hpp>
28+
2229
using namespace aliceVision;
30+
2331
%}

src/aliceVision/camera/Equidistant.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
namespace aliceVision {
1313
namespace camera {
1414

15+
std::shared_ptr<Equidistant> Equidistant::cast(std::shared_ptr<IntrinsicBase> sptr)
16+
{
17+
return std::dynamic_pointer_cast<Equidistant>(sptr);
18+
}
19+
1520
Vec2 Equidistant::transformProject(const Eigen::Matrix4d& pose, const Vec4& pt, bool applyDistortion) const
1621
{
1722
const double rsensor = std::min(sensorWidth(), sensorHeight());

src/aliceVision/camera/Equidistant.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Equidistant : public IntrinsicScaleOffsetDisto
5959

6060
Equidistant* clone() const override { return new Equidistant(*this); }
6161

62+
static std::shared_ptr<Equidistant> cast(std::shared_ptr<IntrinsicBase> sptr);
63+
6264
void assign(const IntrinsicBase& other) override { *this = dynamic_cast<const Equidistant&>(other); }
6365

6466
bool isValid() const override { return _scale(0) > 0 && IntrinsicBase::isValid(); }

src/aliceVision/camera/Equidistant.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// v. 2.0. If a copy of the MPL was not distributed with this file,
55
// You can obtain one at https://mozilla.org/MPL/2.0/.
66

7+
%include <std_shared_ptr.i>
8+
%shared_ptr(aliceVision::camera::Equidistant)
9+
710
%include <aliceVision/camera/IntrinsicScaleOffsetDisto.i>
811
%include <aliceVision/camera/Equidistant.hpp>
912

src/aliceVision/camera/IntrinsicBase.i

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// v. 2.0. If a copy of the MPL was not distributed with this file,
55
// You can obtain one at https://mozilla.org/MPL/2.0/.
66

7-
8-
%include <aliceVision/camera/IntrinsicBase.hpp>
7+
%include <std_shared_ptr.i>
8+
%shared_ptr(aliceVision::camera::IntrinsicBase)
99

1010
%{
1111
#include <aliceVision/camera/IntrinsicBase.hpp>
12-
using namespace aliceVision;
13-
using namespace aliceVision::camera;
1412
%}
13+
14+
%include <aliceVision/camera/IntrinsicBase.hpp>

0 commit comments

Comments
 (0)