Skip to content

Commit

Permalink
[TEST] In visp_core, use 'using namespace VISP_NAMESPACE_NAME;' in th…
Browse files Browse the repository at this point in the history
…e tests
  • Loading branch information
rlagneau committed May 22, 2024
1 parent c6189b0 commit 9edcb33
Show file tree
Hide file tree
Showing 94 changed files with 937 additions and 489 deletions.
50 changes: 27 additions & 23 deletions modules/core/test/camera/testCameraParametersConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
{
std::cout << "* Test operator=()" << std::endl;
Expand Down Expand Up @@ -103,8 +106,8 @@ int main()
vpMeterPixelConversion::convertPoint(cam, x1, y1, u2, v2);
if (!vpMath::equal(u1, u2) || !vpMath::equal(v1, v2)) {
std::cerr << "Error in point conversion without distortion:\n"
<< "u1 = " << u1 << ", u2 = " << u2 << std::endl
<< "v1 = " << v1 << ", v2 = " << v2 << std::endl;
<< "u1 = " << u1 << ", u2 = " << u2 << std::endl
<< "v1 = " << v1 << ", v2 = " << v2 << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -113,8 +116,8 @@ int main()
vpMeterPixelConversion::convertPoint(camDist, x1, y1, u2, v2);
if (!vpMath::equal(u1, u2) || !vpMath::equal(v1, v2)) {
std::cerr << "Error in point conversion without distortion:\n"
<< "u1 = " << u1 << ", u2 = " << u2 << std::endl
<< "v1 = " << v1 << ", v2 = " << v2 << std::endl;
<< "u1 = " << u1 << ", u2 = " << u2 << std::endl
<< "v1 = " << v1 << ", v2 = " << v2 << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -129,7 +132,7 @@ int main()
vpPixelMeterConversion::convertPoint(cameraMatrix, distCoeffs, u1, v1, x2, y2);
if (!vpMath::equal(x1, x2, 1e-6) || !vpMath::equal(y1, y2, 1e-6)) {
std::cerr << "Error in point pixel meter conversion: visp result (" << x1 << ", " << y1 << ") "
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -138,7 +141,7 @@ int main()
vpPixelMeterConversion::convertPoint(cameraMatrix, distCoeffs, ip, x2, y2);
if (!vpMath::equal(x1, x2, 1e-6) || !vpMath::equal(y1, y2, 1e-6)) {
std::cerr << "Error in point pixel meter conversion: visp result (" << x1 << ", " << y1 << ") "
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -147,7 +150,7 @@ int main()
vpMeterPixelConversion::convertPoint(cameraMatrix, distCoeffs, x1, y1, u2, v2);
if (!vpMath::equal(u1, u2, 1e-6) || !vpMath::equal(v1, v2, 1e-6)) {
std::cerr << "Error in point meter pixel conversion: visp result (" << u1 << ", " << v1 << ") "
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -156,7 +159,7 @@ int main()
vpMeterPixelConversion::convertPoint(cameraMatrix, distCoeffs, x1, y1, iP2);
if (vpImagePoint::distance(iP1, iP2) > 1e-6) {
std::cerr << "Error in point meter pixel conversion: visp result (" << u1 << ", " << v1 << ") "
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
return EXIT_FAILURE;
}
}
Expand All @@ -172,7 +175,7 @@ int main()
vpPixelMeterConversion::convertPoint(cameraMatrix, distCoeffs, u1, v1, x2, y2);
if (!vpMath::equal(x1, x2, 1e-6) || !vpMath::equal(y1, y2, 1e-6)) {
std::cerr << "Error in point conversion: visp result (" << x1 << ", " << y1 << ") "
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
<< "differ from OpenCV result (" << x2 << ", " << y2 << ")" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -182,7 +185,7 @@ int main()
vpMeterPixelConversion::convertPoint(cameraMatrix, distCoeffs, x1, y1, u2, v2);
if (!vpMath::equal(u1, u2, 1e-6) || !vpMath::equal(v1, v2, 1e-6)) {
std::cerr << "Error in point meter pixel conversion: visp result (" << u1 << ", " << v1 << ") "
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
<< "differ from OpenCV result (" << u2 << ", " << v2 << ")" << std::endl;
return EXIT_FAILURE;
}
}
Expand All @@ -197,7 +200,7 @@ int main()
vpPixelMeterConversion::convertLine(cameraMatrix, rho_p, theta_p, rho_m2, theta_m2);
if (!vpMath::equal(rho_m1, rho_m2, 1e-6) || !vpMath::equal(theta_m1, theta_m2, 1e-6)) {
std::cerr << "Error in line pixel meter conversion: visp result (" << rho_m1 << ", " << theta_m1 << ") "
<< "differ from OpenCV result (" << rho_m2 << ", " << theta_m1 << ")" << std::endl;
<< "differ from OpenCV result (" << rho_m2 << ", " << theta_m1 << ")" << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -207,7 +210,7 @@ int main()
vpMeterPixelConversion::convertLine(cameraMatrix, rho_m1, theta_m1, rho_p2, theta_p2);
if (!vpMath::equal(rho_p1, rho_p2, 1e-6) || !vpMath::equal(theta_p1, theta_p2, 1e-6)) {
std::cerr << "Error in line meter pixel conversion: visp result (" << rho_p1 << ", " << theta_p1 << ") "
<< "differ from OpenCV result (" << rho_p2 << ", " << theta_p1 << ")" << std::endl;
<< "differ from OpenCV result (" << rho_p2 << ", " << theta_p1 << ")" << std::endl;
return EXIT_FAILURE;
}
}
Expand All @@ -234,8 +237,8 @@ int main()
for (unsigned int j = 0; j < m1.getCols(); j++) {
if (!vpMath::equal(m1[i][j], m1[i][j], 1e-6)) {
std::cerr << "Error in moments pixel meter conversion: visp result for [" << i << "][" << j << "] ("
<< m1[i][j] << ") "
<< "differ from OpenCV result (" << m2[i][j] << ")" << std::endl;
<< m1[i][j] << ") "
<< "differ from OpenCV result (" << m2[i][j] << ")" << std::endl;
return EXIT_FAILURE;
}
}
Expand All @@ -244,7 +247,7 @@ int main()

{
std::cout << "* Compare ViSP and OpenCV ellipse from circle meter pixel conversion without distortion"
<< std::endl;
<< std::endl;
cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px, 0, u0, 0, py, v0, 0, 0, 1);
vpCircle circle;
circle.setWorldCoordinates(0, 0, 1, 0, 0, 0, 0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
Expand All @@ -260,18 +263,18 @@ int main()
if (!vpMath::equal(n20_p1, n20_p2, 1e-6) || !vpMath::equal(n11_p1, n11_p2, 1e-6) ||
!vpMath::equal(n02_p1, n02_p2, 1e-6)) {
std::cerr << "Error in ellipse from circle meter pixel conversion: visp result (" << n20_p1 << ", " << n11_p1
<< ", " << n02_p1 << ") "
<< "differ from OpenCV result (" << n20_p2 << ", " << n11_p2 << ", " << n02_p2 << ")" << std::endl;
<< ", " << n02_p1 << ") "
<< "differ from OpenCV result (" << n20_p2 << ", " << n11_p2 << ", " << n02_p2 << ")" << std::endl;
return EXIT_FAILURE;
}
if (vpImagePoint::distance(center_p1, center_p2) > 1e-6) {
std::cerr << "Error in ellipse from circle meter pixel conversion: visp result (" << center_p1 << ") "
<< "differ from OpenCV result (" << center_p2 << ")" << std::endl;
<< "differ from OpenCV result (" << center_p2 << ")" << std::endl;
return EXIT_FAILURE;
}

std::cout << "* Compare ViSP and OpenCV ellipse from sphere meter pixel conversion without distortion"
<< std::endl;
<< std::endl;
vpSphere sphere;
sphere.setWorldCoordinates(0, 0, 0, 0.1); // X0=0,Y0=0,Z0=0,R=0.1
circle.changeFrame(cMo);
Expand All @@ -282,21 +285,22 @@ int main()
if (!vpMath::equal(n20_p1, n20_p2, 1e-6) || !vpMath::equal(n11_p1, n11_p2, 1e-6) ||
!vpMath::equal(n02_p1, n02_p2, 1e-6)) {
std::cerr << "Error in ellipse from sphere meter pixel conversion: visp result (" << n20_p1 << ", " << n11_p1
<< ", " << n02_p1 << ") "
<< "differ from OpenCV result (" << n20_p2 << ", " << n11_p2 << ", " << n02_p2 << ")" << std::endl;
<< ", " << n02_p1 << ") "
<< "differ from OpenCV result (" << n20_p2 << ", " << n11_p2 << ", " << n02_p2 << ")" << std::endl;
return EXIT_FAILURE;
}
if (vpImagePoint::distance(center_p1, center_p2) > 1e-6) {
std::cerr << "Error in ellipse from sphere meter pixel conversion: visp result (" << center_p1 << ") "
<< "differ from OpenCV result (" << center_p2 << ")" << std::endl;
<< "differ from OpenCV result (" << center_p2 << ")" << std::endl;
return EXIT_FAILURE;
}
}
#endif

std::cout << "Test successful" << std::endl;
return EXIT_SUCCESS;
} catch (const vpException &e) {
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
Expand Down
4 changes: 4 additions & 0 deletions modules/core/test/camera/testJsonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ using json = nlohmann::json; //! json namespace shortcut
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

#include <random>
namespace
{
Expand Down
3 changes: 3 additions & 0 deletions modules/core/test/camera/testXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
#if defined(VISP_HAVE_PUGIXML)

#if defined(_WIN32)
Expand Down
3 changes: 3 additions & 0 deletions modules/core/test/image-with-dataset/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

namespace common_tools
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
static const int g_nearest_neighbor = 0;
static const int g_bilinear = 1;

Expand Down
3 changes: 3 additions & 0 deletions modules/core/test/image-with-dataset/perfColorConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
static std::string ipath = vpIoTools::getViSPImagesDataPath();
static std::string imagePathColor = vpIoTools::createFilePath(ipath, "Klimt/Klimt.ppm");
static std::string imagePathGray = vpIoTools::createFilePath(ipath, "Klimt/Klimt.pgm");
Expand Down
3 changes: 3 additions & 0 deletions modules/core/test/image-with-dataset/perfGaussianFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
static const std::string ipath = vpIoTools::getViSPImagesDataPath();
static std::string imagePath = vpIoTools::createFilePath(ipath, "faces/1280px-Solvay_conference_1927.png");

Expand Down
11 changes: 7 additions & 4 deletions modules/core/test/image-with-dataset/perfImageAddSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
TEST_CASE("Benchmark vpImageTools::imageAdd()", "[benchmark]")
{
const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
Expand Down Expand Up @@ -146,11 +149,11 @@ int main(int argc, char *argv[])
// Build a new parser on top of Catch's
using namespace Catch::clara;
auto cli = session.cli() // Get Catch's composite command line parser
| Opt(runBenchmark) // bind variable to a new option, with a hint string
["--benchmark"] // the option names it will respond to
("run benchmark?"); // description string for the help output
| Opt(runBenchmark) // bind variable to a new option, with a hint string
["--benchmark"] // the option names it will respond to
("run benchmark?"); // description string for the help output

// Now pass the new composite back to Catch so it uses that
// Now pass the new composite back to Catch so it uses that
session.cli(cli);

// Let Catch (using Clara) parse the command line
Expand Down
5 changes: 4 additions & 1 deletion modules/core/test/image-with-dataset/perfImageMorphology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
static std::string ipath = vpIoTools::getViSPImagesDataPath();

TEST_CASE("Benchmark binary image morphology", "[benchmark]")
Expand Down Expand Up @@ -238,7 +241,7 @@ TEST_CASE("Benchmark gray image morphology", "[benchmark]")
}
#endif

int main(int argc, char *argv [])
int main(int argc, char *argv[])
{
Catch::Session session; // There must be exactly one instance

Expand Down
3 changes: 3 additions & 0 deletions modules/core/test/image-with-dataset/perfImageResize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
static const std::string ipath = vpIoTools::getViSPImagesDataPath();
static std::string imagePathColor = vpIoTools::createFilePath(ipath, "Klimt/Klimt.ppm");
static std::string imagePathGray = vpIoTools::createFilePath(ipath, "Klimt/Klimt.pgm");
Expand Down
11 changes: 7 additions & 4 deletions modules/core/test/image-with-dataset/perfImageWarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
namespace
{
static std::string ipath = vpIoTools::getViSPImagesDataPath();
Expand Down Expand Up @@ -341,11 +344,11 @@ int main(int argc, char *argv[])
// Build a new parser on top of Catch's
using namespace Catch::clara;
auto cli = session.cli() // Get Catch's composite command line parser
| Opt(runBenchmark) // bind variable to a new option, with a hint string
["--benchmark"] // the option names it will respond to
("run benchmark?"); // description string for the help output
| Opt(runBenchmark) // bind variable to a new option, with a hint string
["--benchmark"] // the option names it will respond to
("run benchmark?"); // description string for the help output

// Now pass the new composite back to Catch so it uses that
// Now pass the new composite back to Catch so it uses that
session.cli(cli);

// Let Catch (using Clara) parse the command line
Expand Down
4 changes: 4 additions & 0 deletions modules/core/test/image-with-dataset/testColorConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

static const double maxMeanPixelError = 1.5; // conversion to gray produce an error = 1.0
static const unsigned int width = 223, height = 151;

Expand Down
4 changes: 4 additions & 0 deletions modules/core/test/image-with-dataset/testConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

/*!
\example testConversion.cpp
Expand Down
22 changes: 14 additions & 8 deletions modules/core/test/image-with-dataset/testCrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

#include <stdlib.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

/*!
\example testCrop.cpp
Expand Down Expand Up @@ -78,7 +82,7 @@ SYNOPSIS\n\
%s [-i <input image path>] [-o <output image path>]\n\
[-h]\n\
",
name);
name);

fprintf(stdout, "\n\
OPTIONS: Default\n\
Expand Down Expand Up @@ -204,7 +208,8 @@ int main(int argc, const char **argv)
try {
// Create the dirname
vpIoTools::makeDirectory(opath);
} catch (...) {
}
catch (...) {
usage(argv[0], nullptr, ipath, opt_opath, username);
std::cerr << std::endl << "ERROR:" << std::endl;
std::cerr << " Cannot create " << opath << std::endl;
Expand All @@ -219,8 +224,8 @@ int main(int argc, const char **argv)
if (ipath != env_ipath) {
std::cout << std::endl << "WARNING: " << std::endl;
std::cout << " Since -i <visp image path=" << ipath << "> "
<< " is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
<< " we skip the environment variable." << std::endl;
<< " is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
<< " we skip the environment variable." << std::endl;
}
}

Expand All @@ -229,9 +234,9 @@ int main(int argc, const char **argv)
usage(argv[0], nullptr, ipath, opt_opath, username);
std::cerr << std::endl << "ERROR:" << std::endl;
std::cerr << " Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
<< " environment variable to specify the location of the " << std::endl
<< " image path where test images are located." << std::endl
<< std::endl;
<< " environment variable to specify the location of the " << std::endl
<< " image path where test images are located." << std::endl
<< std::endl;
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -261,7 +266,8 @@ int main(int argc, const char **argv)
std::cout << "Write cropped image: " << filename << std::endl;
vpImageIo::write(C, filename);
return EXIT_SUCCESS;
} catch (const vpException &e) {
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e.getStringMessage() << std::endl;
return EXIT_FAILURE;
}
Expand Down
Loading

0 comments on commit 9edcb33

Please sign in to comment.