Skip to content

Commit

Permalink
[WIP] With -DENABLE_VISP_NAMESPACE=OFF, visp_tutorials compiles, with…
Browse files Browse the repository at this point in the history
… -DENABLE_VISP_NAMESPACE=ON compilation error in tutorial-ibvs-4pts-json
  • Loading branch information
rlagneau committed May 27, 2024
1 parent 1a8469e commit ffdf6fe
Show file tree
Hide file tree
Showing 144 changed files with 1,113 additions and 413 deletions.
3 changes: 1 addition & 2 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@

// Defined if the user wants to protect the classes in a dedicated visp namespace
#cmakedefine ENABLE_VISP_NAMESPACE
#ifdef ENABLE_VISP_NAMESPACE
#define VISP_NAMESPACE_NAME visp
#ifdef ENABLE_VISP_NAMESPACE
#define VISP_NAMESPACE_ADDRESSING visp::
#else
#define VISP_NAMESPACE_NAME
#define VISP_NAMESPACE_ADDRESSING
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! \example tutorial-bridge-opencv-camera-param.cpp
#include <iostream>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>

Expand All @@ -11,7 +12,10 @@

int main()
{
//! [Set ViSP camera parameters]
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
//! [Set ViSP camera parameters]
double u0 = 326.6;
double v0 = 215.0;
double px = 582.7;
Expand Down
4 changes: 4 additions & 0 deletions tutorial/bridge/opencv/tutorial-bridge-opencv-image.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! \example tutorial-bridge-opencv-image.cpp
#include <iostream>

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>

Expand All @@ -11,6 +12,9 @@

int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
// From ViSP to OpenCV conversion
{
//! [Load ViSP color image]
Expand Down
6 changes: 5 additions & 1 deletion tutorial/bridge/opencv/tutorial-bridge-opencv-matrix.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! \example tutorial-bridge-opencv-matrix.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>

Expand All @@ -10,6 +11,9 @@
int main()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
{
std::cout << "From OpenCV to ViSP conversion" << std::endl;
//! [Create OpenCV matrix]
Expand Down Expand Up @@ -48,6 +52,6 @@ int main()
std::cout << "M: \n" << M << std::endl;
std::cout << "M_cv: \n" << M_cv << std::endl;
//! [Modify ViSP matrix]
}
}
#endif
}
12 changes: 9 additions & 3 deletions tutorial/computer-vision/pose_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "pose_helper.h"

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

//! [Compute pose]
void computePose(std::vector<vpPoint> &point, const std::vector<vpImagePoint> &ip, const vpCameraParameters &cam,
bool init, vpHomogeneousMatrix &cMo)
Expand Down Expand Up @@ -45,7 +49,8 @@ std::vector<vpImagePoint> track(vpImage<unsigned char> &I, std::vector<vpDot2> &
dot[i].initTracking(I);
vpDisplay::flush(I);
}
} else {
}
else {
for (unsigned int i = 0; i < dot.size(); i++) {
dot[i].track(I);
}
Expand All @@ -64,9 +69,10 @@ std::vector<vpImagePoint> track(vpImage<unsigned char> &I, std::vector<vpDot2> &
}

return ip;
} catch (...) {
}
catch (...) {
std::cout << "Traking lost" << std::endl;
throw(vpException(vpException::fatalError, "Tracking lost"));
}
}
}
#endif
7 changes: 4 additions & 3 deletions tutorial/computer-vision/pose_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
//! [Include]
#include <visp3/blob/vpDot2.h>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpPoint.h>
//! [Include]

void computePose(std::vector<vpPoint> &point, const std::vector<vpImagePoint> &ip, const vpCameraParameters &cam,
bool init, vpHomogeneousMatrix &cMo);
void computePose(std::vector<VISP_NAMESPACE_ADDRESSING vpPoint> &point, const std::vector<VISP_NAMESPACE_ADDRESSING vpImagePoint> &ip, const VISP_NAMESPACE_ADDRESSING vpCameraParameters &cam,
bool init, VISP_NAMESPACE_ADDRESSING vpHomogeneousMatrix &cMo);

#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
std::vector<vpImagePoint> track(vpImage<unsigned char> &I, std::vector<vpDot2> &dot, bool init);
std::vector<VISP_NAMESPACE_ADDRESSING vpImagePoint> track(VISP_NAMESPACE_ADDRESSING vpImage<unsigned char> &I, std::vector<VISP_NAMESPACE_ADDRESSING vpDot2> &dot, bool init);
#endif

#endif
8 changes: 6 additions & 2 deletions tutorial/computer-vision/tutorial-homography-from-points.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! \example tutorial-homography-from-points.cpp

#include <visp3/core/vpConfig.h>
//! [Include]
#include <visp3/vision/vpHomography.h>
//! [Include]
#include <visp3/core/vpMeterPixelConversion.h>

int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
//! [Set 3D points]
double L = 0.1;
std::vector<vpPoint> oP;
Expand Down Expand Up @@ -76,6 +80,6 @@ int main()
//! [Project]
// Project the position in pixel of point 3 from the homography
std::cout << "Estimation from homography: Point 3 in pixels in frame a: " << vpHomography::project(cam, aHb, iPb)
<< std::endl;
//! [Project]
<< std::endl;
//! [Project]
}
5 changes: 5 additions & 0 deletions tutorial/computer-vision/tutorial-pose-from-planar-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Core
#include <visp3/core/vpColorDepthConversion.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMeterPixelConversion.h>
#include <visp3/core/vpXmlParserCamera.h>
Expand All @@ -23,6 +24,10 @@
// Check if std:c++17 or higher
#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) && defined(VISP_HAVE_DISPLAY) && defined(VISP_HAVE_PUGIXML)

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

// Local helper
namespace
{
Expand Down
7 changes: 6 additions & 1 deletion tutorial/computer-vision/tutorial-pose-from-points-image.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*! \example tutorial-pose-from-points-image.cpp */

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
Expand All @@ -12,6 +13,9 @@

int main(int, char *argv[])
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
//! [Read image]
vpImage<unsigned char> I;
Expand Down Expand Up @@ -82,7 +86,8 @@ int main(int, char *argv[])
vpTime::wait(40);
//! [Slow down]
}
} catch (const vpException &e) {
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e.getMessage() << std::endl;
}
}
5 changes: 4 additions & 1 deletion tutorial/computer-vision/tutorial-pose-from-points-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ int main(int argc, char **argv)
#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && defined(VISP_HAVE_PUGIXML) && \
(defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \
defined(HAVE_OPENCV_VIDEOIO) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2))
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
std::string opt_intrinsic_file; // xml file obtained from camera calibration
std::string opt_camera_name; // corresponding camera name in the xml calibration file
Expand Down Expand Up @@ -233,4 +236,4 @@ int main(int argc, char **argv)
"use this example"
<< std::endl;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ int main(int argc, char **argv)
{
#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && \
defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
double opt_square_width = 0.12;
int opt_camera_index = 1; // camera index: 1. Left, 2.Right
Expand Down
9 changes: 7 additions & 2 deletions tutorial/computer-vision/tutorial-pose-from-qrcode-image.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! \example tutorial-pose-from-qrcode-image.cpp */
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpPixelMeterConversion.h>
#include <visp3/detection/vpDetectorQRCode.h>
Expand All @@ -13,6 +14,9 @@
int main(int, char *argv[])
{
#if defined(VISP_HAVE_ZBAR)
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
vpImage<unsigned char> I;
vpImageIo::read(I, vpIoTools::getParent(argv[0]) + "/data/bar-code.pgm");
Expand Down Expand Up @@ -64,7 +68,7 @@ int main(int, char *argv[])

computePose(point, p, cam, init, cMo); // resulting pose is available in cMo var
std::cout << "Pose translation (meter): " << cMo.getTranslationVector().t() << std::endl
<< "Pose rotation (quaternion): " << vpQuaternionVector(cMo.getRotationMatrix()).t() << std::endl;
<< "Pose rotation (quaternion): " << vpQuaternionVector(cMo.getRotationMatrix()).t() << std::endl;
vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none, 3);
}
}
Expand All @@ -76,7 +80,8 @@ int main(int, char *argv[])

vpTime::wait(40);
}
} catch (const vpException &e) {
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e.getMessage() << std::endl;
}
#else
Expand Down
3 changes: 3 additions & 0 deletions tutorial/detection/barcode/tutorial-barcode-detector-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
int main(int argc, const char **argv)
{
#if (defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && (defined(VISP_HAVE_ZBAR) || defined(VISP_HAVE_DMTX))
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int opt_device = 0;
int opt_barcode = 0; // 0=QRCode, 1=DataMatrix

Expand Down
8 changes: 6 additions & 2 deletions tutorial/detection/barcode/tutorial-barcode-detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ int main(int argc, const char **argv)
#if (defined(VISP_HAVE_ZBAR) || defined(VISP_HAVE_DMTX)) && \
(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
//! [Macro defined]
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
vpImage<unsigned char> I;
vpImageIo::read(I, "bar-code.pgm");
Expand All @@ -38,7 +41,7 @@ int main(int argc, const char **argv)
opt_barcode = atoi(argv[i + 1]);
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "Usage: " << argv[0] << " [--code-type <0 for QR code | 1 for DataMatrix code>] [--help] [-h]"
<< std::endl;
<< std::endl;
return EXIT_SUCCESS;
}
}
Expand Down Expand Up @@ -93,7 +96,8 @@ int main(int argc, const char **argv)
vpDisplay::getClick(I);
}
delete detector;
} catch (const vpException &e) {
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e.getMessage() << std::endl;
}
#else
Expand Down
4 changes: 4 additions & 0 deletions tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
using json = nlohmann::json; //! json namespace shortcut
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

typedef enum
{
DETECTION_CONTAINER_MAP = 0,
Expand Down
4 changes: 4 additions & 0 deletions tutorial/detection/dnn/tutorial-dnn-tensorrt-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

#include <sys/stat.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

//! [Preprocess image]
void preprocessImage(cv::Mat &img, float *gpu_input, const nvinfer1::Dims &dims, float meanR, float meanG, float meanB)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! \example tutorial-face-detector-live-threaded.cpp
#include <iostream>

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpTime.h>
#include <visp3/detection/vpDetectorFace.h>
Expand All @@ -16,6 +17,10 @@

#include <opencv2/videoio.hpp>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

// Shared vars
typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;

Expand Down
5 changes: 4 additions & 1 deletion tutorial/detection/face/tutorial-face-detector-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <opencv2/videoio.hpp>
#endif

int main(int argc, const char *argv [])
int main(int argc, const char *argv[])
{
#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_OBJDETECT)
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
std::string opt_face_cascade_name = "./haarcascade_frontalface_alt.xml";
unsigned int opt_device = 0;
Expand Down
11 changes: 8 additions & 3 deletions tutorial/detection/face/tutorial-face-detector.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! \example tutorial-face-detector.cpp
#include <visp3/core/vpConfig.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
Expand All @@ -11,6 +12,9 @@ int main(int argc, const char *argv[])
{
//! [Macro defined]
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_OBJDETECT)
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
//! [Macro defined]
try {
//! [Default settings]
Expand All @@ -25,7 +29,7 @@ int main(int argc, const char *argv[])
opt_video = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "Usage: " << argv[0] << " [--haar <haarcascade xml filename>] [--video <input video file>]"
<< " [--help] [-h]" << std::endl;
<< " [--help] [-h]" << std::endl;
return EXIT_SUCCESS;
}
}
Expand Down Expand Up @@ -83,9 +87,10 @@ int main(int argc, const char *argv[])
}
if (!exit_requested)
vpDisplay::getClick(I);
} catch (const vpException &e) {
std::cout << e.getMessage() << std::endl;
}
catch (const vpException &e) {
std::cout << e.getMessage() << std::endl;
}
#else
(void)argc;
(void)argv;
Expand Down
Loading

0 comments on commit ffdf6fe

Please sign in to comment.