Skip to content

Commit

Permalink
More fixes since some constructors are explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed May 13, 2024
1 parent 89f9f89 commit 632b536
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Description
* Simulation of a 3D visual servoing.
*
*****************************************************************************/
Expand Down Expand Up @@ -267,7 +267,7 @@ int main(int argc, const char **argv)

// Compute the camera translational velocity
vpColVector v(3);
v = lambda * (I - vpColVector::skew(tu_cRcd)) * ctcd;
v = lambda * (I - vpColVector::skew(vpColVector(tu_cRcd))) * ctcd;
// Compute the camera rotational velocity
vpColVector w(3);
w = lambda * tu_cRcd;
Expand Down
6 changes: 3 additions & 3 deletions modules/core/test/math/testColVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int main()
M[i][0] = i;
bench[i] = i;
}
if (test("M", M, bench) == false)
if (test("M", vpColVector(M), bench) == false)
return EXIT_FAILURE;
vpColVector v;
v = M;
Expand All @@ -159,7 +159,7 @@ int main()
vpColVector z1(bench);
if (test("z1", z1, bench) == false)
return EXIT_FAILURE;
vpColVector z2 = bench;
vpColVector z2 = vpColVector(bench);
if (test("z2", z2, bench) == false)
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ int main()
vpColVector y1(bench2);
if (test("y1", y1, bench1) == false)
return EXIT_FAILURE;
vpColVector y2 = bench2;
vpColVector y2 = vpColVector(bench2);
if (test("y2", y2, bench1) == false)
return EXIT_FAILURE;
}
Expand Down
18 changes: 9 additions & 9 deletions modules/core/test/math/testMathUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_CASE("Lon-Lat generator", "[math_lonlat]")
SECTION("NED")
{
std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::ned2ecef);
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::ned2ecef);
for (const auto &ecef_M_ned : ecef_M_ned_vec) {
#ifdef VERBOSE
std::cout << "Lon-Lat ecef_M_ned:\n" << ecef_M_ned << std::endl;
Expand Down Expand Up @@ -108,7 +108,7 @@ TEST_CASE("Lon-Lat generator", "[math_lonlat]")
SECTION("ENU")
{
std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::enu2ecef);
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::enu2ecef);
for (const auto &ecef_M_enu : ecef_M_enu_vec) {
#ifdef VERBOSE
std::cout << "Lon-Lat ecef_M_enu:\n" << ecef_M_enu << std::endl;
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST_CASE("Equidistributed sphere point", "[math_equi_sphere_pts]")
SECTION("NED")
{
std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::ned2ecef);
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::ned2ecef);
CHECK(!ecef_M_ned_vec.empty());
for (const auto &ecef_M_ned : ecef_M_ned_vec) {
#ifdef VERBOSE
Expand Down Expand Up @@ -182,7 +182,7 @@ TEST_CASE("Equidistributed sphere point", "[math_equi_sphere_pts]")
SECTION("ENU")
{
std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::enu2ecef);
vpMath::getLocalTangentPlaneTransformations(lonlatVec, radius, vpMath::enu2ecef);
CHECK(!ecef_M_enu_vec.empty());
for (const auto &ecef_M_enu : ecef_M_enu_vec) {
#ifdef VERBOSE
Expand Down Expand Up @@ -216,7 +216,7 @@ TEST_CASE("Equidistributed sphere point", "[math_equi_sphere_pts]")
TEST_CASE("Look-at", "[math_look_at]")
{
// Set camera to an arbitrary pose (only translation)
vpColVector from_blender = {8.867762565612793, -1.1965436935424805, 2.1211400032043457};
vpColVector from_blender = { 8.867762565612793, -1.1965436935424805, 2.1211400032043457 };
// Transformation from OpenGL to Blender frame
vpHomogeneousMatrix blender_M_gl;
blender_M_gl[0][0] = 0;
Expand All @@ -229,9 +229,9 @@ TEST_CASE("Look-at", "[math_look_at]")
// From is the current camera pose expressed in the OpenGL coordinate system
vpColVector from = (blender_M_gl.getRotationMatrix().t() * from_blender);
// To is the desired point toward the camera must look
vpColVector to = {0, 0, 0};
vpColVector to = { 0, 0, 0 };
// Up is an arbitrary vector
vpColVector up = {0, 1, 0};
vpColVector up = { 0, 1, 0 };

// Compute the look-at transformation
vpHomogeneousMatrix gl_M_cam = vpMath::lookAt(from, to, up);
Expand All @@ -246,10 +246,10 @@ TEST_CASE("Look-at", "[math_look_at]")
std::cout << "\nbl_M_cv:\n" << bl_M_cv << std::endl;

// Ground truth using Blender look-at
vpHomogeneousMatrix bl_M_cv_gt = {0.13372008502483368, 0.22858507931232452, -0.9642965197563171,
vpHomogeneousMatrix bl_M_cv_gt = vpHomogeneousMatrix({ 0.13372008502483368, 0.22858507931232452, -0.9642965197563171,
8.867762565612793, 0.9910191297531128, -0.030843468382954597,
0.13011434674263, -1.1965436935424805, -5.4016709327697754e-08,
-0.9730352163314819, -0.23065657913684845, 2.121140241622925};
-0.9730352163314819, -0.23065657913684845, 2.121140241622925 });
std::cout << "\nbl_M_cv_gt:\n" << bl_M_cv_gt << std::endl;

const double tolerance = 1e-6;
Expand Down
4 changes: 2 additions & 2 deletions modules/core/test/math/testRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ TEST_CASE("Common rotation operations", "[rotation]")
std::cout << "From vpRotationMatrix to vpRzyzVector " << std::endl;
vpRzyzVector rzyz_final;
rzyz_final.buildFrom(R);
CHECK(test("rzyz", rzyz_final, rzyz));
CHECK(test("rzyz", rzyz_final, vpColVector(rzyz)));
std::cout << rzyz_final << std::endl;
}
SECTION("Conversion from and to rzyx vector")
Expand All @@ -388,7 +388,7 @@ TEST_CASE("Common rotation operations", "[rotation]")
std::cout << "From vpRotationMatrix to vpRzyxVector " << std::endl;
vpRzyxVector rzyx_final;
rzyx_final.buildFrom(R);
bool ret = test("rzyx", rzyx_final, rzyx);
bool ret = test("rzyx", rzyx_final, vpColVector(rzyx));
if (ret == false) {
// Euler angle representation is not unique
std::cout << "Rzyx vector differ. Test rotation matrix..." << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions modules/core/test/math/testRowVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main()
M[0][i] = i;
bench[i] = i;
}
if (test("M", M, bench) == false)
if (test("M", vpRowVector(M), bench) == false)
return err;
vpRowVector v;
v = M;
Expand All @@ -137,7 +137,7 @@ int main()
vpRowVector z1(bench);
if (test("z1", z1, bench) == false)
return err;
vpRowVector z2 = bench;
vpRowVector z2 = vpRowVector(bench);
if (test("z2", z2, bench) == false)
return err;
}
Expand Down Expand Up @@ -168,7 +168,7 @@ int main()
vpRowVector y1(bench2);
if (test("y1", y1, bench1) == false)
return err;
vpRowVector y2 = bench2;
vpRowVector y2 = vpRowVector(bench2);
if (test("y2", y2, bench1) == false)
return err;
}
Expand Down
59 changes: 31 additions & 28 deletions modules/detection/test/apriltag-with-dataset/testAprilTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
#include <visp3/vision/vpPose.h>
namespace
{
struct TagGroundTruth {
struct TagGroundTruth
{
std::string m_message;
std::vector<vpImagePoint> m_corners;

TagGroundTruth(const std::string &msg, const std::vector<vpImagePoint> &c) : m_message(msg), m_corners(c) {}
TagGroundTruth(const std::string &msg, const std::vector<vpImagePoint> &c) : m_message(msg), m_corners(c) { }

bool operator==(const TagGroundTruth &b) const
{
Expand Down Expand Up @@ -89,7 +90,8 @@ struct TagGroundTruth {
const vpImagePoint &b = c[i];
error += (a.get_i() - b.get_i()) * (a.get_i() - b.get_i()) + (a.get_j() - b.get_j()) * (a.get_j() - b.get_j());
}
} else {
}
else {
return -1;
}

Expand All @@ -109,16 +111,16 @@ std::ostream &operator<<(std::ostream &os, TagGroundTruth &t)
}
#endif

struct FailedTestCase {
struct FailedTestCase
{
vpDetectorAprilTag::vpAprilTagFamily m_family;
vpDetectorAprilTag::vpPoseEstimationMethod m_method;
int m_tagId;

FailedTestCase(const vpDetectorAprilTag::vpAprilTagFamily &family,
const vpDetectorAprilTag::vpPoseEstimationMethod &method, int tagId)
: m_family(family), m_method(method), m_tagId(tagId)
{
}
{ }

bool operator==(const FailedTestCase &b) const
{
Expand Down Expand Up @@ -195,16 +197,16 @@ TEST_CASE("Apriltag pose estimation test", "[apriltag_pose_estimation_test]")
std::vector<FailedTestCase> ignoreTests = {
FailedTestCase(vpDetectorAprilTag::TAG_STANDARD41h12, vpDetectorAprilTag::LAGRANGE_VIRTUAL_VS, 3),
FailedTestCase(vpDetectorAprilTag::TAG_STANDARD41h12, vpDetectorAprilTag::LAGRANGE_VIRTUAL_VS, 4),
FailedTestCase(vpDetectorAprilTag::TAG_CIRCLE21h7, vpDetectorAprilTag::LAGRANGE_VIRTUAL_VS, 3)};
FailedTestCase(vpDetectorAprilTag::TAG_CIRCLE21h7, vpDetectorAprilTag::LAGRANGE_VIRTUAL_VS, 3) };

vpCameraParameters cam;
cam.initPersProjWithoutDistortion(700.0, 700.0, 320.0, 240.0);

std::map<int, vpHomogeneousMatrix> groundTruthPoses;
for (size_t i = 0; i < nbTags; i++) {
std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), std::string("AprilTag/benchmark/640x480/cMo_") +
std::to_string(i) + std::string(".txt"));
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), std::string("AprilTag/benchmark/640x480/cMo_") +
std::to_string(i) + std::string(".txt"));
std::ifstream file(filename);
groundTruthPoses[static_cast<int>(i)].load(file);
}
Expand All @@ -213,8 +215,8 @@ TEST_CASE("Apriltag pose estimation test", "[apriltag_pose_estimation_test]")
auto family = kv.first;
std::cout << "\nApriltag family: " << family << std::endl;
std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/") + kv.second + std::string("_640x480.png"));
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/") + kv.second + std::string("_640x480.png"));
const double tagSize = tagSize_ * tagSizeScales[family];
REQUIRE(vpIoTools::checkFilename(filename));

Expand Down Expand Up @@ -260,12 +262,12 @@ TEST_CASE("Apriltag pose estimation test", "[apriltag_pose_estimation_test]")
const vpHomogeneousMatrix &cMo_truth = groundTruthPoses[id];
const vpPoseVector pose_truth(cMo_truth);

vpColVector error_translation = pose.getTranslationVector() - pose_truth.getTranslationVector();
vpColVector error_translation = vpColVector(pose.getTranslationVector() - pose_truth.getTranslationVector());
vpColVector error_thetau = vpColVector(pose.getThetaUVector()) - vpColVector(pose_truth.getThetaUVector());
double error_trans = sqrt(error_translation.sumSquare() / 3);
double error_orientation = sqrt(error_thetau.sumSquare() / 3);
std::cout << "\t\t\tTranslation error: " << error_trans << " / Rotation error: " << error_orientation
<< std::endl;
<< std::endl;
CHECK((error_trans < errorTranslationThresh[id] && error_orientation < errorRotationThresh[id]));
}
}
Expand Down Expand Up @@ -299,12 +301,12 @@ TEST_CASE("Apriltag pose estimation test", "[apriltag_pose_estimation_test]")
const vpHomogeneousMatrix &cMo_truth = groundTruthPoses[id];
const vpPoseVector pose_truth(cMo_truth);

vpColVector error_translation = pose.getTranslationVector() - pose_truth.getTranslationVector();
vpColVector error_translation = vpColVector(pose.getTranslationVector() - pose_truth.getTranslationVector());
vpColVector error_thetau = vpColVector(pose.getThetaUVector()) - vpColVector(pose_truth.getThetaUVector());
double error_trans = sqrt(error_translation.sumSquare() / 3);
double error_orientation = sqrt(error_thetau.sumSquare() / 3);
std::cout << "\t\t\tTranslation error: " << error_trans << " / Rotation error: " << error_orientation
<< std::endl;
<< std::endl;
if (std::find(ignoreTests.begin(), ignoreTests.end(),
FailedTestCase(family, method, static_cast<int>(idx))) == ignoreTests.end()) {
CHECK((error_trans < errorTranslationThresh[id] && error_orientation < errorRotationThresh[id]));
Expand Down Expand Up @@ -344,12 +346,12 @@ TEST_CASE("Apriltag pose estimation test", "[apriltag_pose_estimation_test]")
const vpHomogeneousMatrix cMo_truth = groundTruthPoses[id] * oMo2;
const vpPoseVector pose_truth(cMo_truth);

vpColVector error_translation = pose.getTranslationVector() - pose_truth.getTranslationVector();
vpColVector error_translation = vpColVector(pose.getTranslationVector() - pose_truth.getTranslationVector());
vpColVector error_thetau = vpColVector(pose.getThetaUVector()) - vpColVector(pose_truth.getThetaUVector());
double error_trans = sqrt(error_translation.sumSquare() / 3);
double error_orientation = sqrt(error_thetau.sumSquare() / 3);
std::cout << "\t\t\tTranslation error: " << error_trans << " / Rotation error: " << error_orientation
<< std::endl;
<< std::endl;
if (std::find(ignoreTests.begin(), ignoreTests.end(),
FailedTestCase(family, method, static_cast<int>(idx))) == ignoreTests.end()) {
CHECK((error_trans < errorTranslationThresh[id] && error_orientation < errorRotationThresh[id]));
Expand Down Expand Up @@ -380,8 +382,8 @@ TEST_CASE("Apriltag corners accuracy test", "[apriltag_corners_accuracy_test]")
std::map<vpDetectorAprilTag::vpAprilTagFamily, std::map<int, std::vector<vpImagePoint> > > groundTruthCorners;
for (const auto &kv : apriltagMap) {
std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/corners_") + kv.second + std::string(".txt"));
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/corners_") + kv.second + std::string(".txt"));
std::ifstream file(filename);
REQUIRE(file.is_open());

Expand All @@ -403,8 +405,8 @@ TEST_CASE("Apriltag corners accuracy test", "[apriltag_corners_accuracy_test]")
auto family = kv.first;
std::cout << "\nApriltag family: " << family << std::endl;
std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/") + kv.second + std::string("_640x480.png"));
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(),
std::string("AprilTag/benchmark/640x480/") + kv.second + std::string("_640x480.png"));
REQUIRE(vpIoTools::checkFilename(filename));

vpImage<unsigned char> I;
Expand Down Expand Up @@ -463,7 +465,7 @@ TEST_CASE("Apriltag regression test", "[apriltag_regression_test]")
std::map<std::string, TagGroundTruth> mapOfTagsGroundTruth;
{
std::string filename_ground_truth =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/ground_truth_detection.txt");
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/ground_truth_detection.txt");
std::ifstream file_ground_truth(filename_ground_truth.c_str());
REQUIRE(file_ground_truth.is_open());
std::string message = "";
Expand All @@ -482,7 +484,7 @@ TEST_CASE("Apriltag regression test", "[apriltag_regression_test]")
std::map<std::string, vpPoseVector> mapOfPosesGroundTruth;
{
std::string filename_ground_truth =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/ground_truth_pose.txt");
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/ground_truth_pose.txt");
std::ifstream file_ground_truth(filename_ground_truth.c_str());
REQUIRE(file_ground_truth.is_open());
std::string message = "";
Expand All @@ -502,7 +504,8 @@ TEST_CASE("Apriltag regression test", "[apriltag_regression_test]")
TagGroundTruth current(message, p);
if (it == mapOfTagsGroundTruth.end()) {
std::cerr << "Problem with tag decoding (tag_family or id): " << message << std::endl;
} else if (it->second != current) {
}
else if (it->second != current) {
std::cerr << "Problem, current detection:\n" << current << "\nReference:\n" << it->second << std::endl;
}
REQUIRE(it != mapOfTagsGroundTruth.end());
Expand Down Expand Up @@ -538,7 +541,7 @@ TEST_CASE("Apriltag regression test", "[apriltag_regression_test]")
TEST_CASE("Apriltag copy constructor test", "[apriltag_copy_constructor_test]")
{
const std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
REQUIRE(vpIoTools::checkFilename(filename));

vpImage<unsigned char> I;
Expand Down Expand Up @@ -604,7 +607,7 @@ TEST_CASE("Apriltag copy constructor test", "[apriltag_copy_constructor_test]")
TEST_CASE("Apriltag assignment operator test", "[apriltag_assignment_operator_test]")
{
const std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
REQUIRE(vpIoTools::checkFilename(filename));

vpImage<unsigned char> I;
Expand Down Expand Up @@ -670,7 +673,7 @@ TEST_CASE("Apriltag assignment operator test", "[apriltag_assignment_operator_te
TEST_CASE("Apriltag getTagsPoints3D test", "[apriltag_get_tags_points3D_test]")
{
const std::string filename =
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "AprilTag/benchmark/640x480/tag21_07_640x480.png");
REQUIRE(vpIoTools::checkFilename(filename));

vpImage<unsigned char> I;
Expand All @@ -682,7 +685,7 @@ TEST_CASE("Apriltag getTagsPoints3D test", "[apriltag_get_tags_points3D_test]")
const double familyScale = 5.0 / 9;
const double tagSize = 0.25;
std::map<int, double> tagsSize = {
{-1, tagSize * familyScale}, {3, tagSize / 2 * familyScale}, {4, tagSize / 2 * familyScale}};
{-1, tagSize * familyScale}, {3, tagSize / 2 * familyScale}, {4, tagSize / 2 * familyScale} };

vpDetectorAprilTag detector(tagFamily, poseEstimationMethod);

Expand Down

0 comments on commit 632b536

Please sign in to comment.