Skip to content

Commit

Permalink
Merge pull request #1788 from alicevision/dev/swig
Browse files Browse the repository at this point in the history
Add SWIG binding of camera shared pointers
  • Loading branch information
cbentejac authored Dec 4, 2024
2 parents 7d73bc0 + 65f2f36 commit e7a381f
Show file tree
Hide file tree
Showing 29 changed files with 258 additions and 107 deletions.
22 changes: 8 additions & 14 deletions pyTests/camera/test_equidistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pyalicevision import camera as av
from pyalicevision import numeric as avnum

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

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

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

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

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

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

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

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

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

assert intrinsic2.sensorWidth() == 36.0
assert intrinsic2.sensorHeight() == 24.0
Expand Down Expand Up @@ -335,8 +330,7 @@ def test_equidistant_get_set_circle():
assert intrinsic.getCircleCenterY() == center_y

center = intrinsic.getCircleCenter()
# TODO: uncomment when Vec2 is binded
# assert center[0] == center_x and center[1] == center_y
assert avnum.getX(center) == center_x and avnum.getY(center) == center_y


def test_equidistant_ratio_lock_unlock():
Expand Down
4 changes: 2 additions & 2 deletions pyTests/camera/test_pinhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pyalicevision import camera as av
from pyalicevision import numeric as avnum

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

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

assert intrinsic.sensorWidth() == 36.0
assert intrinsic.sensorHeight() == 24.0
Expand Down
10 changes: 4 additions & 6 deletions pyTests/camera/test_undistortion_3de.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pyalicevision import camera as av
from pyalicevision import numeric as avnum

##################
### List of functions:
Expand Down Expand Up @@ -46,8 +47,7 @@ def test_undistortion_3de_constructor():
undistortion = av.Undistortion3DEAnamorphic4(WIDTH, HEIGHT)

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

assert undistortion.getType() == av.UNDISTORTION_3DEANAMORPHIC4

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

undistortion.setSize(HEIGHT, WIDTH)
assert size != undistortion.getSize()
size = undistortion.getSize()
# TODO: uncomment when Vec2 is binded
# assert size[0] == HEIGHT and size[1] == WIDTH
assert avnum.getX(size) == HEIGHT and avnum.getY(size) == WIDTH


@pytest.mark.skip(reason="Vec2 not binded")
Expand Down
10 changes: 4 additions & 6 deletions pyTests/camera/test_undistortion_radial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pyalicevision import camera as av
from pyalicevision import numeric as avnum

##################
### List of functions:
Expand Down Expand Up @@ -46,8 +47,7 @@ def test_undistortion_radial_constructor():
undistortion = av.UndistortionRadialK3(WIDTH, HEIGHT)

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

assert undistortion.getType() == av.UNDISTORTION_RADIALK3

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

undistortion.setSize(HEIGHT, WIDTH)
assert size != undistortion.getSize()
size = undistortion.getSize()
# TODO: uncomment when Vec2 is binded
# assert size[0] == HEIGHT and size[1] == WIDTH
assert avnum.getX(size) == HEIGHT and avnum.getY(size) == WIDTH


@pytest.mark.skip(reason="Vec2 not binded")
Expand Down
13 changes: 6 additions & 7 deletions pyTests/sfmData/test_sfmdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# - ImageInfos& getAncestors()
# - Poses& getPoses() => DONE
# - Rigs& getRigs() => DONE
# - Intrinsics& getIntrinsics() => DONE / Intrinsics derived classes not fully binded
# - Intrinsics& getIntrinsics() => DONE
# - Landmarks& getLandmarks() => DONE
# - Constraints2D& getConstraints2D() => DONE
# - RotationPriors& getRotationPriors() => DONE
Expand Down Expand Up @@ -102,12 +102,11 @@ def test_sfmdata_get_intrinsics():
assert len(intrinsics) == 0, \
"The SfMData object is empty, there should not be any Intrinsic in it"

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


def test_sfmdata_get_landmarks():
Expand Down
8 changes: 8 additions & 0 deletions src/aliceVision/aliceVision.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
%include <aliceVision/global.i>
%include <aliceVision/version.hpp>

%import <aliceVision/numeric/numeric.i>
%import <aliceVision/camera/Camera.i>
%import <aliceVision/geometry/Geometry.i>
%import <aliceVision/hdr/Hdr.i>
Expand All @@ -19,5 +20,12 @@

%{
#include <aliceVision/version.hpp>

//For unknown reason, we need to declare cameras here too
#include <aliceVision/camera/IntrinsicBase.hpp>
#include <aliceVision/camera/Pinhole.hpp>
#include <aliceVision/camera/Equidistant.hpp>

using namespace aliceVision;

%}
5 changes: 5 additions & 0 deletions src/aliceVision/camera/Equidistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
namespace aliceVision {
namespace camera {

std::shared_ptr<Equidistant> Equidistant::cast(std::shared_ptr<IntrinsicBase> sptr)
{
return std::dynamic_pointer_cast<Equidistant>(sptr);
}

Vec2 Equidistant::transformProject(const Eigen::Matrix4d& pose, const Vec4& pt, bool applyDistortion) const
{
const double rsensor = std::min(sensorWidth(), sensorHeight());
Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/camera/Equidistant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Equidistant : public IntrinsicScaleOffsetDisto

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

static std::shared_ptr<Equidistant> cast(std::shared_ptr<IntrinsicBase> sptr);

void assign(const IntrinsicBase& other) override { *this = dynamic_cast<const Equidistant&>(other); }

bool isValid() const override { return _scale(0) > 0 && IntrinsicBase::isValid(); }
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/camera/Equidistant.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

%include <std_shared_ptr.i>
%shared_ptr(aliceVision::camera::Equidistant)

%include <aliceVision/camera/IntrinsicScaleOffsetDisto.i>
%include <aliceVision/camera/Equidistant.hpp>

Expand Down
8 changes: 4 additions & 4 deletions src/aliceVision/camera/IntrinsicBase.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.


%include <aliceVision/camera/IntrinsicBase.hpp>
%include <std_shared_ptr.i>
%shared_ptr(aliceVision::camera::IntrinsicBase)

%{
#include <aliceVision/camera/IntrinsicBase.hpp>
using namespace aliceVision;
using namespace aliceVision::camera;
%}

%include <aliceVision/camera/IntrinsicBase.hpp>
5 changes: 5 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ bool IntrinsicScaleOffset::operator==(const IntrinsicBase& otherBase) const
return _scale.isApprox(other._scale) && _offset.isApprox(other._offset);
}

std::shared_ptr<IntrinsicScaleOffset> IntrinsicScaleOffset::cast(std::shared_ptr<IntrinsicBase> sptr)
{
return std::dynamic_pointer_cast<IntrinsicScaleOffset>(sptr);
}

Vec2 IntrinsicScaleOffset::cam2ima(const Vec2& p) const { return p.cwiseProduct(_scale) + getPrincipalPoint(); }

Eigen::Matrix2d IntrinsicScaleOffset::getDerivativeCam2ImaWrtScale(const Vec2& p) const
Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class IntrinsicScaleOffset : public IntrinsicBase

~IntrinsicScaleOffset() override = default;

static std::shared_ptr<IntrinsicScaleOffset> cast(std::shared_ptr<IntrinsicBase> sptr);

void copyFrom(const IntrinsicScaleOffset& other) { *this = other; }

bool operator==(const IntrinsicBase& otherBase) const override;
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffset.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

%include <std_shared_ptr.i>
%shared_ptr(aliceVision::camera::IntrinsicScaleOffset)

%include <aliceVision/camera/IntrinsicBase.i>
%include <aliceVision/camera/IntrinsicScaleOffset.hpp>

Expand Down
5 changes: 5 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffsetDisto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
namespace aliceVision {
namespace camera {

std::shared_ptr<IntrinsicScaleOffsetDisto> IntrinsicScaleOffsetDisto::cast(std::shared_ptr<IntrinsicBase> sptr)
{
return std::dynamic_pointer_cast<IntrinsicScaleOffsetDisto>(sptr);
}

bool IntrinsicScaleOffsetDisto::operator==(const IntrinsicBase& otherBase) const
{
if (!IntrinsicScaleOffset::operator==(otherBase))
Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffsetDisto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class IntrinsicScaleOffsetDisto : public IntrinsicScaleOffset
}
}

static std::shared_ptr<IntrinsicScaleOffsetDisto> cast(std::shared_ptr<IntrinsicBase> sptr);

void assign(const IntrinsicBase& other) override { *this = dynamic_cast<const IntrinsicScaleOffsetDisto&>(other); }

bool operator==(const IntrinsicBase& otherBase) const override;
Expand Down
3 changes: 3 additions & 0 deletions src/aliceVision/camera/IntrinsicScaleOffsetDisto.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

%include <std_shared_ptr.i>
%shared_ptr(aliceVision::camera::IntrinsicScaleOffsetDisto)

%include <aliceVision/camera/IntrinsicScaleOffset.i>
%include <aliceVision/camera/IntrinsicScaleOffsetDisto.hpp>

Expand Down
5 changes: 5 additions & 0 deletions src/aliceVision/camera/Pinhole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
namespace aliceVision {
namespace camera {

std::shared_ptr<Pinhole> Pinhole::cast(std::shared_ptr<IntrinsicBase> sptr)
{
return std::dynamic_pointer_cast<Pinhole>(sptr);
}

Mat3 Pinhole::K() const
{
Mat3 K;
Expand Down
2 changes: 2 additions & 0 deletions src/aliceVision/camera/Pinhole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Pinhole : public IntrinsicScaleOffsetDisto

void assign(const IntrinsicBase& other) override { *this = dynamic_cast<const Pinhole&>(other); }

static std::shared_ptr<Pinhole> cast(std::shared_ptr<IntrinsicBase> sptr);

double getFocalLengthPixX() const { return _scale(0); }

double getFocalLengthPixY() const { return _scale(1); }
Expand Down
8 changes: 6 additions & 2 deletions src/aliceVision/camera/Pinhole.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

%include <aliceVision/camera/IntrinsicScaleOffsetDisto.i>
%include <aliceVision/camera/Pinhole.hpp>
%include <std_shared_ptr.i>
%shared_ptr(aliceVision::camera::Pinhole)


%{
#include <aliceVision/camera/Pinhole.hpp>
using namespace aliceVision;
using namespace aliceVision::camera;
%}

%include <aliceVision/camera/IntrinsicScaleOffsetDisto.i>
%include <aliceVision/camera/Pinhole.hpp>
2 changes: 2 additions & 0 deletions src/aliceVision/multiview/rotationAveraging/l1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "ceres/ceres.h"
#include "ceres/rotation.h"

#include <aliceVision/numeric/BoxStats.hpp>

#include <map>
#include <queue>
#include <stdint.h>
Expand Down
Loading

0 comments on commit e7a381f

Please sign in to comment.