Skip to content

Updating code to match default OpenCV version on Ubuntu 20.04 (4.X) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ find_package(SofaFramework REQUIRED)
find_package(SofaGeneral REQUIRED)
find_package(SofaGui REQUIRED)

find_package(OpenCV 3.0 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(SofaCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
Expand Down Expand Up @@ -150,7 +150,7 @@ set(SOURCE_FILES
src/ImageProcessing/utils/AddCam.h
)

set(${PROJECT_NAME}_LIBRARIES SofaCore SofaSimulationCommon SofaConstraint ${OpenCV_LIBRARIES} SofaCV)
set(${PROJECT_NAME}_LIBRARIES SofaCore SofaSimulationCommon SofaConstraint Sofa.GL ${OpenCV_LIBRARIES} SofaCV)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand Down
74 changes: 37 additions & 37 deletions src/ImageProcessing/camera/calib/CalibLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,39 @@ class SOFA_IMAGEPROCESSING_API CalibLoader : public ImplicitDataEngine
struct CalibData
{
CalibData() {}
CalibData(const sofa::defaulttype::Matrix3& _K1,
const sofa::defaulttype::Matrix3& _R1,
const sofa::defaulttype::Vector3& _T1,
CalibData(const sofa::type::Matrix3& _K1,
const sofa::type::Matrix3& _R1,
const sofa::type::Vector3& _T1,
const sofa::helper::vector<double>& _delta1,
const sofa::defaulttype::Vec2i _imSize1, double _error1,
const sofa::defaulttype::Matrix3& _K2,
const sofa::defaulttype::Matrix3& _R2,
const sofa::defaulttype::Vector3& _T2,
const sofa::type::Vec2i _imSize1, double _error1,
const sofa::type::Matrix3& _K2,
const sofa::type::Matrix3& _R2,
const sofa::type::Vector3& _T2,
const sofa::helper::vector<double>& _delta2,
const sofa::defaulttype::Vec2i _imSize2, double _error2,
const sofa::defaulttype::Matrix3& _Rs,
const sofa::defaulttype::Vector3& _Ts,
const sofa::defaulttype::Matrix3& _F,
const sofa::defaulttype::Matrix3& _E, double _totalError);

sofa::defaulttype::Vec2i imSize1;
sofa::defaulttype::Matrix3 K1;
sofa::defaulttype::Matrix3 R1;
sofa::defaulttype::Vector3 T1;
const sofa::type::Vec2i _imSize2, double _error2,
const sofa::type::Matrix3& _Rs,
const sofa::type::Vector3& _Ts,
const sofa::type::Matrix3& _F,
const sofa::type::Matrix3& _E, double _totalError);

sofa::type::Vec2i imSize1;
sofa::type::Matrix3 K1;
sofa::type::Matrix3 R1;
sofa::type::Vector3 T1;
sofa::helper::vector<double> delta1;
double error1;

sofa::defaulttype::Vec2i imSize2;
sofa::defaulttype::Matrix3 K2;
sofa::defaulttype::Matrix3 R2;
sofa::defaulttype::Vector3 T2;
sofa::type::Vec2i imSize2;
sofa::type::Matrix3 K2;
sofa::type::Matrix3 R2;
sofa::type::Vector3 T2;
sofa::helper::vector<double> delta2;
double error2;

sofa::defaulttype::Matrix3 Rs;
sofa::defaulttype::Vector3 Ts;
sofa::defaulttype::Matrix3 F;
sofa::defaulttype::Matrix3 E;
sofa::type::Matrix3 Rs;
sofa::type::Vector3 Ts;
sofa::type::Matrix3 F;
sofa::type::Matrix3 E;
double totalError;
};

Expand All @@ -92,24 +92,24 @@ class SOFA_IMAGEPROCESSING_API CalibLoader : public ImplicitDataEngine
bool m_isStereo;
bool m_isInitialized;

sofa::Data<sofa::defaulttype::Vec2i> d_imSize1;
sofa::Data<sofa::defaulttype::Matrix3> d_K1;
sofa::Data<sofa::defaulttype::Matrix3> d_R1;
sofa::Data<sofa::defaulttype::Vector3> d_T1;
sofa::Data<sofa::type::Vec2i> d_imSize1;
sofa::Data<sofa::type::Matrix3> d_K1;
sofa::Data<sofa::type::Matrix3> d_R1;
sofa::Data<sofa::type::Vector3> d_T1;
sofa::Data<sofa::helper::vector<double> > d_delta1;
sofa::Data<double> d_error1;

sofa::Data<sofa::defaulttype::Vec2i> d_imSize2;
sofa::Data<sofa::defaulttype::Matrix3> d_K2;
sofa::Data<sofa::defaulttype::Matrix3> d_R2;
sofa::Data<sofa::defaulttype::Vector3> d_T2;
sofa::Data<sofa::type::Vec2i> d_imSize2;
sofa::Data<sofa::type::Matrix3> d_K2;
sofa::Data<sofa::type::Matrix3> d_R2;
sofa::Data<sofa::type::Vector3> d_T2;
sofa::Data<sofa::helper::vector<double> > d_delta2;
sofa::Data<double> d_error2;

sofa::Data<sofa::defaulttype::Matrix3> d_Rs;
sofa::Data<sofa::defaulttype::Vector3> d_Ts;
sofa::Data<sofa::defaulttype::Matrix3> d_F;
sofa::Data<sofa::defaulttype::Matrix3> d_E;
sofa::Data<sofa::type::Matrix3> d_Rs;
sofa::Data<sofa::type::Vector3> d_Ts;
sofa::Data<sofa::type::Matrix3> d_F;
sofa::Data<sofa::type::Matrix3> d_E;
sofa::Data<double> d_totalError;

protected:
Expand Down
3 changes: 1 addition & 2 deletions src/ImageProcessing/camera/common/CalibratedCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ void CalibratedCamera::computeBBox(const sofa::core::ExecParams *params, bool)
if (p[c] < minBBox[c]) minBBox[c] = p[c];
}
}
this->f_bbox.setValue(
params, sofa::defaulttype::TBoundingBox<double>(minBBox, maxBBox));
this->f_bbox.setValue(sofa::defaulttype::TBoundingBox<double>(minBBox, maxBBox));
}

} // namespace cam
Expand Down
52 changes: 26 additions & 26 deletions src/ImageProcessing/camera/common/CameraSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int CameraSettingsClass =
"transformations")
.add<CameraSettings>();

sofa::defaulttype::Vector2 CameraSettings::get2DFrom3DPosition(
sofa::type::Vector2 CameraSettings::get2DFrom3DPosition(
const Vector3& pt)
{
const Mat3x4d& M = d_M.getValue();
Expand All @@ -29,7 +29,7 @@ sofa::defaulttype::Vector2 CameraSettings::get2DFrom3DPosition(
return Vector2(rx, ry) * 1.0 / rz;
}

sofa::defaulttype::Vector3 CameraSettings::get3DFrom2DPosition(double x,
sofa::type::Vector3 CameraSettings::get3DFrom2DPosition(double x,
double y,
double f)
{
Expand All @@ -46,7 +46,7 @@ sofa::defaulttype::Vector3 CameraSettings::get3DFrom2DPosition(double x,
return R.transposed() * (point3D - t);
}

sofa::defaulttype::Vector3 CameraSettings::get3DFrom2DPosition(const Vector2& p,
sofa::type::Vector3 CameraSettings::get3DFrom2DPosition(const Vector2& p,
double f)
{
return get3DFrom2DPosition(p[0], p[1], f);
Expand All @@ -72,7 +72,7 @@ void CameraSettings::getCornersPosition(Vector3& p1, Vector3& p2, Vector3& p3,
p4 = get3DFrom2DPosition(0, h, f);
}

const sofa::defaulttype::Mat3x4d& CameraSettings::getProjectionMatrix() const
const sofa::type::Mat3x4d& CameraSettings::getProjectionMatrix() const
{
return d_M.getValue();
}
Expand All @@ -86,7 +86,7 @@ void CameraSettings::setProjectionMatrix(const Mat3x4d& M)
recalculate3DCorners();
}

const sofa::defaulttype::Matrix3& CameraSettings::getIntrinsicCameraMatrix()
const sofa::type::Matrix3& CameraSettings::getIntrinsicCameraMatrix()
const
{
return d_K.getValue();
Expand All @@ -104,13 +104,13 @@ void CameraSettings::setIntrinsicCameraMatrix(const Matrix3& K, bool update)
recalculate3DCorners();
}

const sofa::helper::vector<double>& CameraSettings::getDistortionCoefficients()
const sofa::type::vector<double>& CameraSettings::getDistortionCoefficients()
const
{
return d_distCoefs.getValue();
}
void CameraSettings::setDistortionCoefficients(
const sofa::helper::vector<double>& distCoefs)
const sofa::type::vector<double>& distCoefs)
{
// Nothing to do, distortion coefficients are not (yet?) taken into account in
// OpenGL
Expand All @@ -119,7 +119,7 @@ void CameraSettings::setDistortionCoefficients(
recalculate3DCorners();
}

const sofa::defaulttype::Matrix3& CameraSettings::getRotationMatrix() const
const sofa::type::Matrix3& CameraSettings::getRotationMatrix() const
{
return d_R.getValue();
}
Expand All @@ -136,7 +136,7 @@ void CameraSettings::setRotationMatrix(const Matrix3& R, bool update)
recalculate3DCorners();
}

const sofa::defaulttype::Vector3& CameraSettings::getPosition() const
const sofa::type::Vector3& CameraSettings::getPosition() const
{
return d_t.getValue();
}
Expand All @@ -153,7 +153,7 @@ void CameraSettings::setPosition(const Vector3& t, bool update)
recalculate3DCorners();
}

const sofa::defaulttype::Vec2i& CameraSettings::getImageSize() const
const sofa::type::Vec2i& CameraSettings::getImageSize() const
{
return d_imageSize.getValue();
}
Expand All @@ -168,7 +168,7 @@ void CameraSettings::setImageSize(const Vec2i& imgSize, bool update)

recalculate3DCorners();
}
const sofa::defaulttype::Matrix4& CameraSettings::getGLProjection() const
const sofa::type::Matrix4& CameraSettings::getGLProjection() const
{
return d_glProjection.getValue();
}
Expand All @@ -180,7 +180,7 @@ void CameraSettings::setGLProjection(const Matrix4& glProjection)

recalculate3DCorners();
}
const sofa::defaulttype::Matrix4& CameraSettings::getGLModelview() const
const sofa::type::Matrix4& CameraSettings::getGLModelview() const
{
return d_glModelview.getValue();
}
Expand All @@ -193,7 +193,7 @@ void CameraSettings::setGLModelview(const Matrix4& glModelview)
recalculate3DCorners();
}

const sofa::defaulttype::Vec<4, int>& CameraSettings::getGLViewport() const
const sofa::type::Vec<4, int>& CameraSettings::getGLViewport() const
{
return d_glViewport.getValue();
}
Expand All @@ -204,7 +204,7 @@ void CameraSettings::setGLViewport(const Vector4& glViewport)
recalculate3DCorners();
}

const sofa::defaulttype::Vector2& CameraSettings::getGLZClip() const
const sofa::type::Vector2& CameraSettings::getGLZClip() const
{
return d_zClip.getValue();
}
Expand All @@ -215,7 +215,7 @@ void CameraSettings::setGLZClip(const Vector2& zClip)

recalculate3DCorners();
}
const sofa::defaulttype::Quat& CameraSettings::getOrientation() const
const sofa::type::Quaternion& CameraSettings::getOrientation() const
{
return d_orientation.getValue();
}
Expand All @@ -231,7 +231,7 @@ void CameraSettings::setOrientation(const Quat& orientation)
recalculate3DCorners();
}

const sofa::defaulttype::Matrix3& CameraSettings::get2DScaleMatrix() const
const sofa::type::Matrix3& CameraSettings::get2DScaleMatrix() const
{
return d_scale2D.getValue();
}
Expand All @@ -252,7 +252,7 @@ void CameraSettings::setFocalDistance(double f)
recalculate3DCorners();
}

const sofa::defaulttype::Matrix3& CameraSettings::get2DTranslationMatrix() const
const sofa::type::Matrix3& CameraSettings::get2DTranslationMatrix() const
{
return d_translate2D.getValue();
}
Expand All @@ -265,7 +265,7 @@ void CameraSettings::set2DTranslationMatrix(const Matrix3& translation2D)
recalculate3DCorners();
}

const sofa::helper::vector<sofa::defaulttype::Vector3>&
const sofa::type::vector<sofa::type::Vector3>&
CameraSettings::getCorners() const
{
return d_3DCorners.getValue();
Expand Down Expand Up @@ -559,7 +559,7 @@ void CameraSettings::recalculate3DCorners()
Vector3 p1, p2, p3, p4;
this->getCornersPosition(p1, p2, p3, p4,
(d_f.getValue() != -1) ? (d_f.getValue()) : (1.0f));
sofa::helper::vector<Vector3>& corners3D = *d_3DCorners.beginEdit();
sofa::type::vector<Vector3>& corners3D = *d_3DCorners.beginEdit();
corners3D.clear();
corners3D.push_back(p1);
corners3D.push_back(p2);
Expand All @@ -569,16 +569,16 @@ void CameraSettings::recalculate3DCorners()
}

/// Projects a point p on a plane defined by a Point A and a normal n
sofa::defaulttype::Vector3 orthoProj(const sofa::defaulttype::Vector3& p,
const sofa::defaulttype::Vector3& A,
const sofa::defaulttype::Vector3& n)
sofa::type::Vector3 orthoProj(const sofa::type::Vector3& p,
const sofa::type::Vector3& A,
const sofa::type::Vector3& n)
{
double lambda = ((A * n) - (p * n)) / (n * n);
return p + lambda * n;
}

double length(const sofa::defaulttype::Vector3& a,
const sofa::defaulttype::Vector3& b)
double length(const sofa::type::Vector3& a,
const sofa::type::Vector3& b)
{
return sqrt((a.x() - b.x()) * (a.x() - b.x()) +
(a.y() - b.y()) * (a.y() - b.y()) +
Expand Down Expand Up @@ -732,8 +732,8 @@ void CameraSettings::buildFromKRT()
decomposeCV();
composeM();
composeGL();
sofa::defaulttype::Matrix3 rot;
sofa::defaulttype::Quat q = getOrientation();
sofa::type::Matrix3 rot;
sofa::type::Quat q = getOrientation();
q.toMatrix(rot);

Vector3 camPos = getPosition();
Expand Down
Loading