From 4aa365f366f000bed3f69c47fbd54e19a589308b Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 13 Dec 2024 16:54:43 +0100 Subject: [PATCH] Fix compat with OpenCV 2.4.9.1 coming with Ubuntu 16.04 - allow to use cv::VideoCapture --- .../tracking/tutorial-tracking-blob.dox | 16 +- ...rial-tracking-mb-generic-apriltag-live.dox | 12 +- example/calibration/calibrate-camera.cpp | 5 + example/manual/ogre/HelloWorldOgre.cpp | 26 ++- .../manual/ogre/HelloWorldOgreAdvanced.cpp | 25 ++- .../servoPioneerPoint2DDepth.cpp | 64 +++--- ...servoPioneerPoint2DDepthWithoutVpServo.cpp | 35 ++-- .../visp3/core/vpMeterPixelConversion.h | 2 +- .../visp3/core/vpPixelMeterConversion.h | 2 +- .../core/test/math/catchMatrixCholesky.cpp | 8 +- modules/io/include/visp3/io/vpVideoReader.h | 8 +- modules/io/include/visp3/io/vpVideoWriter.h | 15 +- modules/io/src/video/vpVideoReader.cpp | 20 +- modules/io/src/video/vpVideoWriter.cpp | 12 +- .../rgb-depth/testRealSense2_D435_opencv.cpp | 2 +- .../test/rgb-depth/testRealSense2_SR300.cpp | 2 +- .../tracker/blob/include/visp3/blob/vpDot2.h | 4 +- .../klt/include/visp3/klt/vpKltOpencv.h | 13 +- modules/tracker/klt/src/vpKltOpencv.cpp | 5 +- modules/vision/CMakeLists.txt | 3 +- .../vision/include/visp3/vision/vpKeyPoint.h | 11 +- modules/vision/src/key-point/vpKeyPoint.cpp | 6 +- .../keypoint-with-dataset/testKeyPoint-3.cpp | 2 +- .../keypoint-with-dataset/testKeyPoint-4.cpp | 5 + .../keypoint-with-dataset/testKeyPoint-5.cpp | 7 +- .../keypoint-with-dataset/testKeyPoint-6.cpp | 2 + .../test/feature/catchLuminanceMapping.cpp | 185 +++++++++--------- .../tutorial-pose-from-points-live.cpp | 62 +++--- .../tutorial-barcode-detector-live.cpp | 35 +++- .../tutorial-dnn-object-detection-live.cpp | 29 ++- .../dnn/tutorial-dnn-tensorrt-live.cpp | 1 + .../tutorial-face-detector-live-threaded.cpp | 31 ++- .../face/tutorial-face-detector-live.cpp | 38 ++-- ...orial-detection-object-mbt2-deprecated.cpp | 8 + .../object/tutorial-detection-object-mbt2.cpp | 8 + .../tag/tutorial-apriltag-detector-live.cpp | 60 +++--- .../tutorial-grabber-opencv-threaded.cpp | 35 ++-- tutorial/grabber/tutorial-grabber-opencv.cpp | 31 +-- tutorial/grabber/tutorial-video-reader.cpp | 2 +- tutorial/grabber/tutorial-video-recorder.cpp | 44 ++++- .../color/tutorial-hsv-range-tuner.cpp | 2 +- tutorial/tracking/blob/CMakeLists.txt | 3 +- .../tutorial-blob-tracker-live-firewire.cpp | 94 --------- .../blob/tutorial-blob-tracker-live-v4l2.cpp | 97 --------- .../blob/tutorial-blob-tracker-live.cpp | 167 ++++++++++++++++ tutorial/tracking/keypoint/CMakeLists.txt | 2 +- ...v4l2.cpp => tutorial-klt-tracker-live.cpp} | 52 ++++- .../tutorial-klt-tracker-with-reinit.cpp | 27 ++- .../keypoint/tutorial-klt-tracker.cpp | 36 +++- ...torial-mb-generic-tracker-apriltag-rs2.cpp | 50 +++-- ...ial-mb-generic-tracker-apriltag-webcam.cpp | 91 +++++---- .../tutorial-mb-generic-tracker-live.cpp | 82 ++++---- .../tutorial-me-ellipse-tracker.cpp | 106 ++++++++-- .../moving-edges/tutorial-me-line-tracker.cpp | 106 ++++++++-- 54 files changed, 1132 insertions(+), 664 deletions(-) delete mode 100644 tutorial/tracking/blob/tutorial-blob-tracker-live-firewire.cpp delete mode 100644 tutorial/tracking/blob/tutorial-blob-tracker-live-v4l2.cpp create mode 100644 tutorial/tracking/blob/tutorial-blob-tracker-live.cpp rename tutorial/tracking/keypoint/{tutorial-klt-tracker-live-v4l2.cpp => tutorial-klt-tracker-live.cpp} (63%) diff --git a/doc/tutorial/tracking/tutorial-tracking-blob.dox b/doc/tutorial/tracking/tutorial-tracking-blob.dox index 98103cdf0c..49f4dca61b 100644 --- a/doc/tutorial/tracking/tutorial-tracking-blob.dox +++ b/doc/tutorial/tracking/tutorial-tracking-blob.dox @@ -32,40 +32,40 @@ a v4l2 live camera that can be an usb camera, or a Raspberry Pi camera module. \subsection live-firewire From a firewire live camera -The following code also available in tutorial-blob-tracker-live-firewire.cpp file provided in ViSP source code tree +The following code also available in tutorial-blob-tracker-live.cpp file provided in ViSP source code tree allows to grab images from a firewire camera and track a blob. The initialisation is done with a user mouse click on a pixel that belongs to the blob. To acquire images from a firewire camera we use vp1394TwoGrabber class on unix-like systems or vp1394CMUGrabber class under Windows. These classes are described in the \ref tutorial-grabber. -\include tutorial-blob-tracker-live-firewire.cpp +\include tutorial-blob-tracker-live.cpp From now, we assume that you have successfully followed the \ref tutorial-getting-started and the \ref tutorial-grabber. Here after we explain the new lines that are introduced. -\snippet tutorial-blob-tracker-live-firewire.cpp Construction +\snippet tutorial-blob-tracker-live.cpp Construction Then we are modifying some default settings to allow drawings in overlay the contours pixels and the position of the center of gravity with a thickness of 2 pixels. -\snippet tutorial-blob-tracker-live-firewire.cpp Setting +\snippet tutorial-blob-tracker-live.cpp Setting Then we are waiting for a user initialization throw a mouse click event in the blob to track. -\snippet tutorial-blob-tracker-live-firewire.cpp Init +\snippet tutorial-blob-tracker-live.cpp Init The tracker is now initialized. The tracking can be performed on new images: -\snippet tutorial-blob-tracker-live-firewire.cpp Track +\snippet tutorial-blob-tracker-live.cpp Track \subsection live-v4l2 From a v4l2 live camera -The following code also available in tutorial-blob-tracker-live-v4l2.cpp file provided in ViSP source code tree allows +The following code also available in tutorial-blob-tracker-live.cpp file provided in ViSP source code tree allows to grab images from a camera compatible with video for linux two driver (v4l2) and track a blob. Webcams or more generally USB cameras, but also the Raspberry Pi Camera Module can be considered. To acquire images from a v4l2 camera we use vpV4l2Grabber class on unix-like systems. This class is described in the \ref tutorial-grabber. -\include tutorial-blob-tracker-live-v4l2.cpp +\include tutorial-blob-tracker-live.cpp The code is the same than the one presented in the previous subsection, except that here we use the vpV4l2Grabber class to grab images from usb cameras. Here we have also modified the while loop in order to catch an exception when diff --git a/doc/tutorial/tracking/tutorial-tracking-mb-generic-apriltag-live.dox b/doc/tutorial/tracking/tutorial-tracking-mb-generic-apriltag-live.dox index 7addccd264..2fbf7a35e5 100644 --- a/doc/tutorial/tracking/tutorial-tracking-mb-generic-apriltag-live.dox +++ b/doc/tutorial/tracking/tutorial-tracking-mb-generic-apriltag-live.dox @@ -105,7 +105,7 @@ tutorials given in \ref tutorial_install_src. Once build, to see the options that are available, just run: \code $ ./tutorial-mb-generic-tracker-apriltag-webcam --help -Usage: ./tutorial-mb-generic-tracker-apriltag-webcam [--input ] [--cube_size ] [--tag-size ] [--quad-decimate ] [--nthreads ] [--intrinsic ] [--camera-name ] [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>] [--display-off] [--texture] [--projection_error <30 - 100>] [--help] +Usage: ./tutorial-mb-generic-tracker-apriltag-webcam [--input ] [--cube-size ] [--tag-size ] [--quad-decimate ] [--nthreads ] [--intrinsic ] [--camera-name ] [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>] [--display-off] [--texture] [--projection-error <30 - 100>] [--help] \endcode To test the tracker on a 12.5 cm wide cube that has an AprilTag of size 8 by 8 cm, and enable moving-edges and @@ -126,7 +126,7 @@ $ ./tutorial-mb-generic-tracker-apriltag-webcam --input 1 \endcode - The default size of the cube is 0.125 meter large. To use rather a 0.20 meter large cube, run: \code -$ ./tutorial-mb-generic-tracker-apriltag-webcam --cube_size 0.20 +$ ./tutorial-mb-generic-tracker-apriltag-webcam --cube-size 0.20 \endcode - The AprilTag size is 0.08 by 0.08 meters. To change the tag size to let say 0.10 meter square, use: \code @@ -160,7 +160,7 @@ $ ./tutorial-mb-generic-tracker-apriltag-webcam --display_off The default value of this threshold is set to 40 degrees. To decrease this threshold to 30 degrees (meaning that we accept less projection error and thus trigger a new AprilTag detection more often) you may run: \code -$ ./tutorial-mb-generic-tracker-apriltag-webcam --projection_error 30 +$ ./tutorial-mb-generic-tracker-apriltag-webcam --projection-error 30 \endcode \subsection mb_generic_apriltag_webcam_result Expected results @@ -202,7 +202,7 @@ provided in the tutorials available from \ref tutorial_install_src. Once build, to see the options that are available, just run: \code $ ./tutorial-mb-generic-tracker-apriltag-rs2 --help -Usage: ./tutorial-mb-generic-tracker-apriltag-rs2 [--cube_size ] [--tag-size ] [--quad-decimate ] [--nthreads ] [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>] [--display-off] [--texture] [--depth] [--projection_error <30 - 100>] [--help] +Usage: ./tutorial-mb-generic-tracker-apriltag-rs2 [--cube-size ] [--tag-size ] [--quad-decimate ] [--nthreads ] [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>] [--display-off] [--texture] [--depth] [--projection-error <30 - 100>] [--help] \endcode To test the tracker on a 12.5 cm wide cube that has an AprilTag of size 8 by 8 cm, and enable moving-edges, keypoints @@ -224,7 +224,7 @@ $ ./tutorial-mb-generic-tracker-apriltag-rs2 By default, the following settings are used:
- Default size of the cube is 0.125 meter large. To use rather a 0.20 meter large cube, run: \code -$ ./tutorial-mb-generic-tracker-apriltag-rs2 --cube_size 0.20 +$ ./tutorial-mb-generic-tracker-apriltag-rs2 --cube-size 0.20 \endcode - The AprilTag size is 0.08 by 0.08 meters. To change the tag size to let say 0.10 meter square, use: \code @@ -251,7 +251,7 @@ $ ./tutorial-mb-generic-tracker-apriltag-rs2 --display_off The default value of this threshold is set to 40 degrees. To decrease this threshold to 30 degrees (meaning that we accept less projection error and thus trigger a new AprilTag detection more often) you may run: \code -$ ./tutorial-mb-generic-tracker-apriltag-webcam --projection_error 30 +$ ./tutorial-mb-generic-tracker-apriltag-webcam --projection-error 30 \endcode \subsection mb_generic_apriltag_realsense_result Expected results diff --git a/example/calibration/calibrate-camera.cpp b/example/calibration/calibrate-camera.cpp index 8ba5462ea5..d4c4ba4c68 100644 --- a/example/calibration/calibrate-camera.cpp +++ b/example/calibration/calibrate-camera.cpp @@ -44,6 +44,11 @@ #elif defined(HAVE_OPENCV_CALIB) #include #endif + +#if defined(HAVE_OPENCV_CONTRIB) +#include // Needed on Ubuntu 16.04 with OpenCV 2.4.9.1 +#endif + #include #include #include diff --git a/example/manual/ogre/HelloWorldOgre.cpp b/example/manual/ogre/HelloWorldOgre.cpp index 36083fcf96..c977a1e1f2 100644 --- a/example/manual/ogre/HelloWorldOgre.cpp +++ b/example/manual/ogre/HelloWorldOgre.cpp @@ -36,21 +36,31 @@ \example HelloWorldOgre.cpp \brief Example that shows how to exploit the vpAROgre class. - */ #include +#include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + #include #include -#include #include #include #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif int main() @@ -61,7 +71,9 @@ int main() try { #if defined(VISP_HAVE_OGRE) -#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(HAVE_OPENCV_VIDEOIO) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) // Image to stock gathered data // Here we acquire a color image. The consequence will be that @@ -79,7 +91,7 @@ int main() vp1394TwoGrabber grabber; grabber.open(I); grabber.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) // OpenCV to gather images cv::VideoCapture grabber(0); // open the default camera if (!grabber.isOpened()) { // check if we succeeded @@ -142,7 +154,7 @@ int main() // Acquire a new image #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) grabber.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) grabber >> frame; vpImageConvert::convert(frame, I); #endif diff --git a/example/manual/ogre/HelloWorldOgreAdvanced.cpp b/example/manual/ogre/HelloWorldOgreAdvanced.cpp index 7aa04c37c7..e9c7313d75 100644 --- a/example/manual/ogre/HelloWorldOgreAdvanced.cpp +++ b/example/manual/ogre/HelloWorldOgreAdvanced.cpp @@ -41,16 +41,27 @@ #include +#include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + #include #include -#include #include #include #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif #ifdef ENABLE_VISP_NAMESPACE @@ -114,7 +125,9 @@ int main() { try { #if defined(VISP_HAVE_OGRE) -#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(HAVE_OPENCV_VIDEOIO) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) // Image to store gathered data // Here we acquire a grey level image. The consequence will be that @@ -139,7 +152,7 @@ int main() // the image size grabber.open(I); grabber.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) // OpenCV to gather images cv::VideoCapture grabber(0); // open the default camera if (!grabber.isOpened()) { // check if we succeeded @@ -171,7 +184,7 @@ int main() // Acquire a new image #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) grabber.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) grabber >> frame; vpImageConvert::convert(frame, I); #endif diff --git a/example/servo-pioneer/servoPioneerPoint2DDepth.cpp b/example/servo-pioneer/servoPioneerPoint2DDepth.cpp index 4e4b13a145..79c93b0b27 100644 --- a/example/servo-pioneer/servoPioneerPoint2DDepth.cpp +++ b/example/servo-pioneer/servoPioneerPoint2DDepth.cpp @@ -36,6 +36,15 @@ #include +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + #include #include #include @@ -53,11 +62,15 @@ #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) || defined(HAVE_OPENCV_VIDEOIO) +#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) #if defined(VISP_HAVE_PIONEER) #define TEST_COULD_BE_ACHIEVED @@ -65,31 +78,28 @@ #endif #endif -#undef VISP_HAVE_OPENCV // To use a firewire camera -#undef VISP_HAVE_V4L2 // To use a firewire camera - - /*! - \example servoPioneerPoint2DDepth.cpp +/*! + \example servoPioneerPoint2DDepth.cpp - Example that shows how to control the Pioneer mobile robot by IBVS visual - servoing with respect to a blob. The current visual features that are used - are s = (x, log(Z/Z*)). The desired one are s* = (x*, 0), with: - - x the abscise of the point corresponding to the blob center of gravity - measured at each iteration, - - x* the desired abscise position of the point (x* = 0) - - Z the depth of the point measured at each iteration - - Z* the desired depth of the point equal to the initial one. + Example that shows how to control the Pioneer mobile robot by IBVS visual + servoing with respect to a blob. The current visual features that are used + are s = (x, log(Z/Z*)). The desired one are s* = (x*, 0), with: + - x the abscise of the point corresponding to the blob center of gravity + measured at each iteration, + - x* the desired abscise position of the point (x* = 0) + - Z the depth of the point measured at each iteration + - Z* the desired depth of the point equal to the initial one. - The degrees of freedom that are controlled are (vx, wz), where wz is the - rotational velocity and vx the translational velocity of the mobile platform - at point M located at the middle between the two wheels. + The degrees of freedom that are controlled are (vx, wz), where wz is the + rotational velocity and vx the translational velocity of the mobile platform + at point M located at the middle between the two wheels. - The feature x allows to control wy, while log(Z/Z*) allows to control vz. - The value of x is measured thanks to a blob tracker. - The value of Z is estimated from the surface of the blob that is - proportional to the depth Z. + The feature x allows to control wy, while log(Z/Z*) allows to control vz. + The value of x is measured thanks to a blob tracker. + The value of Z is estimated from the surface of the blob that is + proportional to the depth Z. - */ +*/ #ifdef TEST_COULD_BE_ACHIEVED int main(int argc, char **argv) { @@ -137,7 +147,7 @@ int main(int argc, char **argv) vpCameraParameters cam; // Create the camera framegrabber -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) int device = 1; std::cout << "Use device: " << device << std::endl; cv::VideoCapture g(device); // open the default camera @@ -181,7 +191,7 @@ int main(int argc, char **argv) #endif // Acquire an image from the grabber -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #else @@ -262,7 +272,7 @@ int main(int argc, char **argv) while (1) { // Acquire a new image -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #else diff --git a/example/servo-pioneer/servoPioneerPoint2DDepthWithoutVpServo.cpp b/example/servo-pioneer/servoPioneerPoint2DDepthWithoutVpServo.cpp index 40bd30b641..060ece2519 100644 --- a/example/servo-pioneer/servoPioneerPoint2DDepthWithoutVpServo.cpp +++ b/example/servo-pioneer/servoPioneerPoint2DDepthWithoutVpServo.cpp @@ -34,9 +34,19 @@ *****************************************************************************/ #include +#include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + #include #include -#include #include #include #include @@ -51,11 +61,15 @@ #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) || defined(HAVE_OPENCV_VIDEOIO) +#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) #if defined(VISP_HAVE_PIONEER) #define TEST_COULD_BE_ACHIEVED @@ -63,9 +77,6 @@ #endif #endif -#undef VISP_HAVE_OPENCV // To use a firewire camera -#undef VISP_HAVE_V4L2 // To use a firewire camera - /*! \example servoPioneerPoint2DDepthWithoutVpServo.cpp @@ -87,7 +98,7 @@ The value of Z is estimated from the surface of the blob that is proportional to the depth Z. - */ + */ #ifdef TEST_COULD_BE_ACHIEVED int main(int argc, char **argv) { @@ -135,7 +146,7 @@ int main(int argc, char **argv) vpCameraParameters cam; // Create the camera framegrabber -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) int device = 1; std::cout << "Use device: " << device << std::endl; cv::VideoCapture g(device); // open the default camera @@ -179,7 +190,7 @@ int main(int argc, char **argv) #endif // Acquire an image from the grabber -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #else @@ -249,7 +260,7 @@ int main(int argc, char **argv) while (1) { // Acquire a new image -#if defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #else @@ -276,7 +287,7 @@ int main(int argc, char **argv) L.stack(L_Z); // not constant since it corresponds to log(Z/Z*) that // evolves at each iteration -// Update the global error s-s* + // Update the global error s-s* vpColVector error; error.stack(s_x.error(s_xd, vpFeaturePoint::selectX())); error.stack(s_Z.error(s_Zd)); diff --git a/modules/core/include/visp3/core/vpMeterPixelConversion.h b/modules/core/include/visp3/core/vpMeterPixelConversion.h index 8e620ce6e1..70c2f07f0a 100644 --- a/modules/core/include/visp3/core/vpMeterPixelConversion.h +++ b/modules/core/include/visp3/core/vpMeterPixelConversion.h @@ -47,7 +47,7 @@ #include #if defined(VISP_HAVE_OPENCV) -#include +#include #endif BEGIN_VISP_NAMESPACE diff --git a/modules/core/include/visp3/core/vpPixelMeterConversion.h b/modules/core/include/visp3/core/vpPixelMeterConversion.h index be6bb66ebd..6b4c0b1844 100644 --- a/modules/core/include/visp3/core/vpPixelMeterConversion.h +++ b/modules/core/include/visp3/core/vpPixelMeterConversion.h @@ -45,7 +45,7 @@ #include #if defined(VISP_HAVE_OPENCV) -#include +#include #endif BEGIN_VISP_NAMESPACE diff --git a/modules/core/test/math/catchMatrixCholesky.cpp b/modules/core/test/math/catchMatrixCholesky.cpp index 391ca816ba..373d325c67 100644 --- a/modules/core/test/math/catchMatrixCholesky.cpp +++ b/modules/core/test/math/catchMatrixCholesky.cpp @@ -142,9 +142,9 @@ TEST_CASE("3 x 3 input", "[cholesky]") } #endif -// There is a bug with OpenCV 3.1.0 +// There is a bug with OpenCV 2.4.9 and OpenCV 3.1.0 // See https://answers.opencv.org/question/99704/cholesky-function-in-opencv/ -#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x030100) +#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x020409) && (VISP_HAVE_OPENCV_VERSION != 0x030100) SECTION("OPENCV") { vpMatrix L = M.choleskyByOpenCV(); @@ -183,9 +183,9 @@ TEST_CASE("4 x 4 input", "[cholesky]") } #endif -// There is a bug with OpenCV 3.1.0 +// There is a bug with OpenCV 2.4.9 and OpenCV 3.1.0 // See https://answers.opencv.org/question/99704/cholesky-function-in-opencv/ -#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x030100) +#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x020409) && (VISP_HAVE_OPENCV_VERSION != 0x030100) SECTION("OPENCV") { vpMatrix L = M.choleskyByOpenCV(); diff --git a/modules/io/include/visp3/io/vpVideoReader.h b/modules/io/include/visp3/io/vpVideoReader.h index 1e2a9ebb3a..67a1b79daf 100644 --- a/modules/io/include/visp3/io/vpVideoReader.h +++ b/modules/io/include/visp3/io/vpVideoReader.h @@ -41,11 +41,13 @@ #include +#include #include -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) #include +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include #endif BEGIN_VISP_NAMESPACE @@ -180,7 +182,7 @@ class VISP_EXPORT vpVideoReader : public vpFrameGrabber private: //! To read sequences of images vpDiskGrabber *m_imSequence; -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) //! To read video files with OpenCV cv::VideoCapture m_capture; cv::Mat m_frame; diff --git a/modules/io/include/visp3/io/vpVideoWriter.h b/modules/io/include/visp3/io/vpVideoWriter.h index 99601c7b95..28bf69c6a5 100644 --- a/modules/io/include/visp3/io/vpVideoWriter.h +++ b/modules/io/include/visp3/io/vpVideoWriter.h @@ -43,9 +43,14 @@ #include -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) #include -#include +#endif + #endif BEGIN_VISP_NAMESPACE @@ -163,7 +168,7 @@ BEGIN_VISP_NAMESPACE class VISP_EXPORT vpVideoWriter { private: -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::VideoWriter m_writer; int m_fourcc; double m_framerate; @@ -236,7 +241,7 @@ class VISP_EXPORT vpVideoWriter void saveFrame(vpImage &I); void saveFrame(vpImage &I); -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) inline void setCodec(const int fourcc_codec) { m_fourcc = fourcc_codec; } #endif @@ -252,7 +257,7 @@ class VISP_EXPORT vpVideoWriter * * \note Framerate can only be set when OpenCV > 2.1.0. */ -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) inline void setFramerate(const double framerate) { m_framerate = framerate; } #else inline void setFramerate(const double dummy) { (void)dummy; } diff --git a/modules/io/src/video/vpVideoReader.cpp b/modules/io/src/video/vpVideoReader.cpp index b5f85268d2..51a6c9f7cf 100644 --- a/modules/io/src/video/vpVideoReader.cpp +++ b/modules/io/src/video/vpVideoReader.cpp @@ -50,7 +50,7 @@ BEGIN_VISP_NAMESPACE */ vpVideoReader::vpVideoReader() : vpFrameGrabber(), m_imSequence(nullptr), -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) m_capture(), m_frame(), m_lastframe_unknown(false), #endif m_formatType(FORMAT_UNKNOWN), m_videoName(), m_frameName(), m_initFileName(false), m_isOpen(false), m_frameCount(0), @@ -132,7 +132,7 @@ void vpVideoReader::getProperties() m_frameRate = -1.; } else if (isVideoExtensionSupported()) { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) m_capture.open(m_videoName.c_str()); if (!m_capture.isOpened()) { @@ -185,7 +185,7 @@ void vpVideoReader::open(vpImage &I) m_frameCount = m_firstFrame; if (isVideoExtensionSupported()) { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if VISP_HAVE_OPENCV_VERSION >= 0x030000 m_capture.set(cv::CAP_PROP_POS_FRAMES, m_firstFrame - 1); @@ -218,7 +218,7 @@ void vpVideoReader::open(vpImage &I) m_frameCount = m_firstFrame; if (isVideoExtensionSupported()) { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if VISP_HAVE_OPENCV_VERSION >= 0x030000 m_capture.set(cv::CAP_PROP_POS_FRAMES, m_firstFrame - 1); @@ -266,7 +266,7 @@ void vpVideoReader::acquire(vpImage &I) m_imSequence->setImageNumber(m_frameCount); } } -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) else { m_capture >> m_frame; if (m_frameStep == 1) { @@ -361,7 +361,7 @@ void vpVideoReader::acquire(vpImage &I) m_imSequence->setImageNumber(m_frameCount); } } -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) else { m_capture >> m_frame; if (m_frameStep == 1) { @@ -452,7 +452,7 @@ bool vpVideoReader::getFrame(vpImage &I, long frame_index) } } else { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) if (!m_capture.set(cv::CAP_PROP_POS_FRAMES, frame_index)) { // Couldn't find the %ld th frame", frame_index @@ -529,7 +529,7 @@ bool vpVideoReader::getFrame(vpImage &I, long frame_index) } } else { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if VISP_HAVE_OPENCV_VERSION >= 0x030000 if (!m_capture.set(cv::CAP_PROP_POS_FRAMES, frame_index)) { // Couldn't find the %ld th frame", frame_index @@ -718,7 +718,7 @@ void vpVideoReader::findLastFrameIndex() } } -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if VISP_HAVE_OPENCV_VERSION >= 0x030000 else if (!m_lastFrameIndexIsSet) { m_lastFrame = (long)m_capture.get(cv::CAP_PROP_FRAME_COUNT); @@ -771,7 +771,7 @@ void vpVideoReader::findFirstFrameIndex() m_imSequence->setImageNumber(m_firstFrame); } } -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) else if (!m_firstFrameIndexIsSet) { m_firstFrame = 1L; diff --git a/modules/io/src/video/vpVideoWriter.cpp b/modules/io/src/video/vpVideoWriter.cpp index e196b9f573..69a0b2517a 100644 --- a/modules/io/src/video/vpVideoWriter.cpp +++ b/modules/io/src/video/vpVideoWriter.cpp @@ -50,13 +50,13 @@ BEGIN_VISP_NAMESPACE */ vpVideoWriter::vpVideoWriter() : -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) m_writer(), m_framerate(25.0), #endif m_formatType(FORMAT_UNKNOWN), m_videoName(), m_frameName(), m_initFileName(false), m_isOpen(false), m_frameCount(0), m_firstFrame(0), m_width(0), m_height(0), m_frameStep(1) { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) m_fourcc = cv::VideoWriter::fourcc('P', 'I', 'M', '1'); #else @@ -125,7 +125,7 @@ void vpVideoWriter::open(vpImage &I) } else if (m_formatType == FORMAT_AVI || m_formatType == FORMAT_MPEG || m_formatType == FORMAT_MPEG4 || m_formatType == FORMAT_MOV) { -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) m_writer = cv::VideoWriter(m_videoName, m_fourcc, m_framerate, cv::Size(static_cast(I.getWidth()), static_cast(I.getHeight()))); @@ -165,7 +165,7 @@ void vpVideoWriter::open(vpImage &I) } else if (m_formatType == FORMAT_AVI || m_formatType == FORMAT_MPEG || m_formatType == FORMAT_MPEG4 || m_formatType == FORMAT_MOV) { -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) m_writer = cv::VideoWriter(m_videoName, m_fourcc, m_framerate, cv::Size(static_cast(I.getWidth()), static_cast(I.getHeight()))); @@ -205,7 +205,7 @@ void vpVideoWriter::saveFrame(vpImage &I) m_frameName = std::string(name); } else { -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::Mat matFrame; vpImageConvert::convert(I, matFrame); m_writer << matFrame; @@ -238,7 +238,7 @@ void vpVideoWriter::saveFrame(vpImage &I) m_frameName = std::string(name); } else { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) cv::Mat matFrame, rgbMatFrame; vpImageConvert::convert(I, matFrame); diff --git a/modules/sensor/test/rgb-depth/testRealSense2_D435_opencv.cpp b/modules/sensor/test/rgb-depth/testRealSense2_D435_opencv.cpp index 06b4a146a3..2e39d8d0b6 100644 --- a/modules/sensor/test/rgb-depth/testRealSense2_D435_opencv.cpp +++ b/modules/sensor/test/rgb-depth/testRealSense2_D435_opencv.cpp @@ -48,7 +48,7 @@ #include #include -#include +#include namespace { diff --git a/modules/sensor/test/rgb-depth/testRealSense2_SR300.cpp b/modules/sensor/test/rgb-depth/testRealSense2_SR300.cpp index 41c50c9947..dc2f847be2 100644 --- a/modules/sensor/test/rgb-depth/testRealSense2_SR300.cpp +++ b/modules/sensor/test/rgb-depth/testRealSense2_SR300.cpp @@ -57,7 +57,7 @@ #if VISP_HAVE_OPENCV_VERSION >= 0x030000 #include -#include +#include #endif #ifdef ENABLE_VISP_NAMESPACE diff --git a/modules/tracker/blob/include/visp3/blob/vpDot2.h b/modules/tracker/blob/include/visp3/blob/vpDot2.h index b6a7d030b3..d0befc5882 100644 --- a/modules/tracker/blob/include/visp3/blob/vpDot2.h +++ b/modules/tracker/blob/include/visp3/blob/vpDot2.h @@ -103,10 +103,10 @@ BEGIN_VISP_NAMESPACE * can also be used to find a certain type of dots in the full image. * * The following sample code available in - * tutorial-blob-tracker-live-firewire.cpp shows how to grab images from a + * tutorial-blob-tracker-live.cpp shows how to grab images from a * firewire camera, track a blob and display the tracking results. * - * \include tutorial-blob-tracker-live-firewire.cpp + * \include tutorial-blob-tracker-live.cpp * A line by line explanation of the previous example is provided in * \ref tutorial-tracking-blob. * diff --git a/modules/tracker/klt/include/visp3/klt/vpKltOpencv.h b/modules/tracker/klt/include/visp3/klt/vpKltOpencv.h index 98bb462da4..6da9df8d28 100644 --- a/modules/tracker/klt/include/visp3/klt/vpKltOpencv.h +++ b/modules/tracker/klt/include/visp3/klt/vpKltOpencv.h @@ -1,6 +1,6 @@ /* * ViSP, open source Visual Servoing Platform software. - * Copyright (C) 2005 - 2023 by Inria. All rights reserved. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,14 +39,15 @@ implemented with opencv. */ -#ifndef _vpKltOpencv_h_ -#define _vpKltOpencv_h_ +#ifndef VP_KLT_OPENCV_H +#define VP_KLT_OPENCV_H -#include #include -#include -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) +#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) + +#include +#include #include #include diff --git a/modules/tracker/klt/src/vpKltOpencv.cpp b/modules/tracker/klt/src/vpKltOpencv.cpp index 66a4e4de3d..76cb6172d7 100644 --- a/modules/tracker/klt/src/vpKltOpencv.cpp +++ b/modules/tracker/klt/src/vpKltOpencv.cpp @@ -1,6 +1,6 @@ /* * ViSP, open source Visual Servoing Platform software. - * Copyright (C) 2005 - 2023 by Inria. All rights reserved. + * Copyright (C) 2005 - 2024 by Inria. All rights reserved. * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ #include -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) +#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) #include @@ -95,7 +95,6 @@ void vpKltOpencv::initTracking(const cv::Mat &I, const cv::Mat &mask) { m_next_points_id = 0; - // cvtColor(I, m_gray, cv::COLOR_BGR2GRAY); I.copyTo(m_gray); for (size_t i = 0; i < 2; i++) { diff --git a/modules/vision/CMakeLists.txt b/modules/vision/CMakeLists.txt index 9bd28a1f80..17e97d1c18 100644 --- a/modules/vision/CMakeLists.txt +++ b/modules/vision/CMakeLists.txt @@ -68,7 +68,8 @@ if(USE_OPENCV) set(OpenCV_REQUIRED_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS}) vp_list_filterout(OpenCV_REQUIRED_LIB_COMPONENTS "opencv_*") # We import only required OpenCV libraries - list(APPEND OpenCV_REQUIRED_LIB_COMPONENTS "opencv_legacy" "opencv_xfeatures2d" "opencv_features" "opencv_3d" "opencv_calib" "opencv_calib3d" "opencv_nonfree" "opencv_flann") + # Note: opencv_contrib is required with OpenCV 2.4.9.1 coming with Ubuntu 16.04 + list(APPEND OpenCV_REQUIRED_LIB_COMPONENTS "opencv_legacy" "opencv_xfeatures2d" "opencv_features" "opencv_3d" "opencv_calib" "opencv_calib3d" "opencv_nonfree" "opencv_flann" "opencv_contrib") foreach(component_ ${OpenCV_REQUIRED_LIB_COMPONENTS}) string(TOUPPER "${component_}" component_UP) diff --git a/modules/vision/include/visp3/vision/vpKeyPoint.h b/modules/vision/include/visp3/vision/vpKeyPoint.h index ed24747d0d..24a1f4e880 100644 --- a/modules/vision/include/visp3/vision/vpKeyPoint.h +++ b/modules/vision/include/visp3/vision/vpKeyPoint.h @@ -64,7 +64,7 @@ #include #include -#include +#include #if defined(HAVE_OPENCV_FEATURES2D) #include @@ -76,7 +76,6 @@ #if defined(HAVE_OPENCV_IMGPROC) #include -//#include #endif #if defined(HAVE_OPENCV_NONFREE) @@ -326,12 +325,16 @@ class VISP_EXPORT vpKeyPoint : public vpBasicKeyPoint # endif #else // OpenCV < 5.0.0 # if defined(HAVE_OPENCV_FEATURES2D) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) DETECTOR_AGAST, //!< AGAST detector DETECTOR_AKAZE, //!< AKAZE detector +#endif DETECTOR_BRISK, //!< BRISK detector DETECTOR_FAST, //!< FAST detector DETECTOR_GFTT, //!< GFTT detector +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) DETECTOR_KAZE, //!< KAZE detector +#endif DETECTOR_MSER, //!< MSER detector DETECTOR_ORB, //!< ORB detector DETECTOR_SimpleBlob, //!< SimpleBlob detector @@ -373,9 +376,13 @@ class VISP_EXPORT vpKeyPoint : public vpBasicKeyPoint # endif #else // opencv < 5.0.0 # if defined(HAVE_OPENCV_FEATURES2D) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) DESCRIPTOR_AKAZE, //!< AKAZE descriptor +#endif DESCRIPTOR_BRISK, //!< BRISK descriptor +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) DESCRIPTOR_KAZE, //!< KAZE descriptor +#endif DESCRIPTOR_ORB, //!< ORB descriptor # endif # if defined(HAVE_OPENCV_XFEATURES2D) diff --git a/modules/vision/src/key-point/vpKeyPoint.cpp b/modules/vision/src/key-point/vpKeyPoint.cpp index b4556d13c6..ac7965418d 100644 --- a/modules/vision/src/key-point/vpKeyPoint.cpp +++ b/modules/vision/src/key-point/vpKeyPoint.cpp @@ -49,7 +49,7 @@ #endif #if (VISP_HAVE_OPENCV_VERSION <0x050000) -#include +#include #endif #if defined(HAVE_OPENCV_XFEATURES2D) @@ -2240,10 +2240,12 @@ void vpKeyPoint::initFeatureNames() #endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) m_mapOfDetectorNames[DETECTOR_BRISK] = "BRISK"; +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) m_mapOfDetectorNames[DETECTOR_KAZE] = "KAZE"; m_mapOfDetectorNames[DETECTOR_AKAZE] = "AKAZE"; m_mapOfDetectorNames[DETECTOR_AGAST] = "AGAST"; #endif +#endif #if defined(HAVE_OPENCV_XFEATURES2D) m_mapOfDetectorNames[DETECTOR_STAR] = "STAR"; m_mapOfDetectorNames[DETECTOR_MSD] = "MSD"; @@ -2275,9 +2277,11 @@ void vpKeyPoint::initFeatureNames() m_mapOfDescriptorNames[DESCRIPTOR_SURF] = "SURF"; #endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) m_mapOfDescriptorNames[DESCRIPTOR_KAZE] = "KAZE"; m_mapOfDescriptorNames[DESCRIPTOR_AKAZE] = "AKAZE"; #endif +#endif #if defined(HAVE_OPENCV_XFEATURES2D) m_mapOfDescriptorNames[DESCRIPTOR_DAISY] = "DAISY"; m_mapOfDescriptorNames[DESCRIPTOR_LATCH] = "LATCH"; diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-3.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-3.cpp index 0797ceb7ec..5ebac247dd 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-3.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-3.cpp @@ -50,7 +50,7 @@ #endif #if defined(HAVE_OPENCV_FEATURES2D) -#include +#include #endif #include diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp index b3eb6596ae..98baa5e3f7 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp @@ -237,8 +237,13 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis cv::Ptr matcher; #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) detector = cv::ORB::create(500, 1.2f, 1); extractor = cv::ORB::create(500, 1.2f, 1); +#elif (VISP_HAVE_OPENCV_VERSION >= 0x020301) + detector = cv::FeatureDetector::create("ORB"); + extractor = cv::DescriptorExtractor::create("ORB"); +#endif #endif matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp index abd874a9c7..486cc1ef3c 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp @@ -201,14 +201,19 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis detectorNames.push_back("ORB"); #endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) detectorNames.push_back("PyramidAGAST"); - detectorNames.push_back("AGAST"); detectorNames.push_back("PyramidBRISK"); + detectorNames.push_back("AGAST"); +#endif + detectorNames.push_back("PyramidBRISK"); detectorNames.push_back("BRISK"); +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) detectorNames.push_back("PyramidKAZE"); detectorNames.push_back("KAZE"); detectorNames.push_back("PyramidAKAZE"); detectorNames.push_back("AKAZE"); #endif +#endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) #if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \ diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-6.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-6.cpp index 51eac2f8b5..1a961b41fb 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-6.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-6.cpp @@ -238,9 +238,11 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis descriptorNames.push_back("BoostDesc"); #endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XFEATURES2D)) +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) descriptorNames.push_back("KAZE"); descriptorNames.push_back("AKAZE"); #endif +#endif #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) std::string detectorName = "FAST"; #endif diff --git a/modules/visual_features/test/feature/catchLuminanceMapping.cpp b/modules/visual_features/test/feature/catchLuminanceMapping.cpp index c8282a90cf..f0af70125b 100644 --- a/modules/visual_features/test/feature/catchLuminanceMapping.cpp +++ b/modules/visual_features/test/feature/catchLuminanceMapping.cpp @@ -37,16 +37,17 @@ * \example catchLuminanceMapping.cpp */ -#include - -#include +#include -#include -#include #if defined(VISP_HAVE_CATCH2) #include +#include +#include +#include +#include + #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -314,103 +315,97 @@ SCENARIO("Using DCT features", "[visual_features]") { GIVEN("A matrix") { - std::vector> data = { + vpMatrix M1({ + {0.0, 1.0, 2.0}, + {3.0, 4.0, 5.0}, + {6.0, 7.0, 8.0} + }); + vpColVector v( + { 0.0, 1.0, 3.0, 6.0, 4.0, 2.0, 5.0, 7.0, 8.0 } + ); + vpMatrix M2({ + {0.0, 1.0, 5.0}, + {2.0, 4.0, 6.0}, + {3.0, 7.0, 8.0} + }); + std::tuple data(M1, v, M2); + + WHEN("Building the associated zigzag indexing matrix") + { + vpMatrix m = std::get<0>(data); + vpColVector contentAsZigzag = std::get<1>(data); + const vpMatrix mAfterWriterVec = std::get<2>(data); + vpLuminanceDCT::vpMatrixZigZagIndex zigzag; + zigzag.init(m.getRows(), m.getCols()); + vpColVector s; + THEN("Calling getValues with wrong matrix rows throws") { - vpMatrix({ - {0.0, 1.0, 2.0}, - {3.0, 4.0, 5.0}, - {6.0, 7.0, 8.0} - }), - vpColVector( - { 0.0, 1.0, 3.0, 6.0, 4.0, 2.0, 5.0, 7.0, 8.0 } - ), - vpMatrix({ - {0.0, 1.0, 5.0}, - {2.0, 4.0, 6.0}, - {3.0, 7.0, 8.0} - }) + vpMatrix wrongM(m.getRows() + 1, m.getCols()); + REQUIRE_THROWS(zigzag.getValues(wrongM, 0, 2, s)); } - }; - for (unsigned int i = 0; i < data.size(); ++i) { - WHEN("Building the associated zigzag indexing matrix") + THEN("Calling getValues with wrong matrix cols throws") { - vpMatrix m = std::get<0>(data[i]); - vpColVector contentAsZigzag = std::get<1>(data[i]); - const vpMatrix mAfterWriterVec = std::get<2>(data[i]); - vpLuminanceDCT::vpMatrixZigZagIndex zigzag; - zigzag.init(m.getRows(), m.getCols()); - vpColVector s; - THEN("Calling getValues with wrong matrix rows throws") - { - vpMatrix wrongM(m.getRows() + 1, m.getCols()); - REQUIRE_THROWS(zigzag.getValues(wrongM, 0, 2, s)); - } - THEN("Calling getValues with wrong matrix cols throws") - { - vpMatrix wrongM(m.getRows(), m.getCols() + 1); - REQUIRE_THROWS(zigzag.getValues(wrongM, 0, 2, s)); - } - THEN("Calling getValues with wrong start and end arguments throws") - { - REQUIRE_THROWS(zigzag.getValues(m, 2, 1, s)); - } - THEN("Calling getValues and querying all values returns correct result") - { - REQUIRE_NOTHROW(zigzag.getValues(m, 0, m.size(), s)); - REQUIRE(s == contentAsZigzag); - } - THEN("Calling getValues and querying a subset of the values is correct") - { - REQUIRE_NOTHROW(zigzag.getValues(m, 0, m.size() / 2, s)); - REQUIRE(s == contentAsZigzag.extract(0, m.size() / 2)); - REQUIRE_NOTHROW(zigzag.getValues(m, m.size() / 2, m.size(), s)); - REQUIRE(s == contentAsZigzag.extract(m.size() / 2, m.size() - m.size() / 2)); - } - THEN("Calling setValues with wrong matrix rows throws") - { - vpMatrix wrongM(m.getRows() + 1, m.getCols()); - REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, 0, wrongM)); - } - THEN("Calling setValues with wrong matrix cols throws") - { - vpMatrix wrongM(m.getRows(), m.getCols() + 1); - REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, 0, wrongM)); - } - - THEN("Calling setValues with wrong start and vector size arguments throws") - { - REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, m.size() - contentAsZigzag.size() + 1, m)); - } - - THEN("Calling setValues leads to expected result") - { - vpMatrix mWrite(m.getRows(), m.getCols()); - vpColVector powered = contentAsZigzag; - for (unsigned i = 0; i < powered.size(); ++i) { - powered[i] *= powered[i]; - } - vpColVector poweredRead; - REQUIRE_NOTHROW(zigzag.setValues(powered, 0, mWrite)); - REQUIRE_NOTHROW(zigzag.getValues(mWrite, 0, mWrite.size(), poweredRead)); - REQUIRE(powered == poweredRead); - - vpColVector indices = contentAsZigzag; - for (unsigned i = 0; i < powered.size(); ++i) { - indices[i] = static_cast(i); - } - vpColVector indicesRead; - REQUIRE_NOTHROW(zigzag.setValues(indices, 0, mWrite)); - REQUIRE(mWrite == mAfterWriterVec); - - vpMatrix m2(m.getRows(), m.getCols(), 0.0); - zigzag.setValues(contentAsZigzag.extract(0, 3), 0, m2); + vpMatrix wrongM(m.getRows(), m.getCols() + 1); + REQUIRE_THROWS(zigzag.getValues(wrongM, 0, 2, s)); + } + THEN("Calling getValues with wrong start and end arguments throws") + { + REQUIRE_THROWS(zigzag.getValues(m, 2, 1, s)); + } + THEN("Calling getValues and querying all values returns correct result") + { + REQUIRE_NOTHROW(zigzag.getValues(m, 0, m.size(), s)); + REQUIRE(s == contentAsZigzag); + } + THEN("Calling getValues and querying a subset of the values is correct") + { + REQUIRE_NOTHROW(zigzag.getValues(m, 0, m.size() / 2, s)); + REQUIRE(s == contentAsZigzag.extract(0, m.size() / 2)); + REQUIRE_NOTHROW(zigzag.getValues(m, m.size() / 2, m.size(), s)); + REQUIRE(s == contentAsZigzag.extract(m.size() / 2, m.size() - m.size() / 2)); + } + THEN("Calling setValues with wrong matrix rows throws") + { + vpMatrix wrongM(m.getRows() + 1, m.getCols()); + REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, 0, wrongM)); + } + THEN("Calling setValues with wrong matrix cols throws") + { + vpMatrix wrongM(m.getRows(), m.getCols() + 1); + REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, 0, wrongM)); + } - vpColVector s2; - zigzag.getValues(m2, 0, 3, s2); - REQUIRE(s2 == contentAsZigzag.extract(0, 3)); + THEN("Calling setValues with wrong start and vector size arguments throws") + { + REQUIRE_THROWS(zigzag.setValues(contentAsZigzag, m.size() - contentAsZigzag.size() + 1, m)); + } + THEN("Calling setValues leads to expected result") + { + vpMatrix mWrite(m.getRows(), m.getCols()); + vpColVector powered = contentAsZigzag; + for (unsigned i = 0; i < powered.size(); ++i) { + powered[i] *= powered[i]; + } + vpColVector poweredRead; + REQUIRE_NOTHROW(zigzag.setValues(powered, 0, mWrite)); + REQUIRE_NOTHROW(zigzag.getValues(mWrite, 0, mWrite.size(), poweredRead)); + REQUIRE(powered == poweredRead); + + vpColVector indices = contentAsZigzag; + for (unsigned i = 0; i < powered.size(); ++i) { + indices[i] = static_cast(i); } + vpColVector indicesRead; + REQUIRE_NOTHROW(zigzag.setValues(indices, 0, mWrite)); + REQUIRE(mWrite == mAfterWriterVec); + + vpMatrix m2(m.getRows(), m.getCols(), 0.0); + zigzag.setValues(contentAsZigzag.extract(0, 3), 0, m2); + vpColVector s2; + zigzag.getValues(m2, 0, 3, s2); + REQUIRE(s2 == contentAsZigzag.extract(0, 3)); } } diff --git a/tutorial/computer-vision/tutorial-pose-from-points-live.cpp b/tutorial/computer-vision/tutorial-pose-from-points-live.cpp index bf7171107b..0a5f356dca 100644 --- a/tutorial/computer-vision/tutorial-pose-from-points-live.cpp +++ b/tutorial/computer-vision/tutorial-pose-from-points-live.cpp @@ -1,5 +1,24 @@ /*! \example tutorial-pose-from-points-live.cpp */ +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#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(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2)) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + #ifdef VISP_HAVE_MODULE_SENSOR #include #include @@ -12,27 +31,16 @@ #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif #include "pose_helper.h" -// Comment / uncomment following lines to use the specific 3rd party compatible with your camera -//! [Undef grabber] -// #undef VISP_HAVE_V4L2 -// #undef VISP_HAVE_DC1394 -// #undef VISP_HAVE_CMU1394 -// #undef VISP_HAVE_FLYCAPTURE -// #undef VISP_HAVE_REALSENSE2 -// #undef HAVE_OPENCV_VIDEOIO -//! [Undef grabber] - 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 @@ -112,7 +120,7 @@ int main(int argc, char **argv) std::cout << "Read camera parameters from Realsense device" << std::endl; cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; cv::VideoCapture g(opt_device); // Open the default camera if (!g.isOpened()) { // Check if we succeeded @@ -173,7 +181,7 @@ int main(int argc, char **argv) #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -230,17 +238,13 @@ int main(int argc, char **argv) catch (const vpException &e) { std::cout << "Catch an exception: " << e.getMessage() << std::endl; } -#elif (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) - (void)argc; - (void)argv; - std::cout << "Install a 3rd party dedicated to frame grabbing (dc1394, cmu1394, v4l2, OpenCV, FlyCapture, " - "Realsense2), configure and build ViSP again to use this example" - << std::endl; +} + #else - (void)argc; - (void)argv; - std::cout << "Install a 3rd party dedicated to image display (X11, GDI, OpenCV), configure and build ViSP again to " - "use this example" - << std::endl; -#endif + +int main() +{ + std::cout << "There are missing 3rd parties to run this tutorial" << std::endl; } + +#endif diff --git a/tutorial/detection/barcode/tutorial-barcode-detector-live.cpp b/tutorial/detection/barcode/tutorial-barcode-detector-live.cpp index d7889fda28..72d0964e03 100644 --- a/tutorial/detection/barcode/tutorial-barcode-detector-live.cpp +++ b/tutorial/detection/barcode/tutorial-barcode-detector-live.cpp @@ -1,5 +1,18 @@ //! \example tutorial-barcode-detector-live.cpp +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if (defined(VISP_HAVE_ZBAR) || defined(VISP_HAVE_DMTX)) && (defined(VISP_HAVE_V4L2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + #include #include #include @@ -10,13 +23,14 @@ #include #endif -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif 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 @@ -52,7 +66,7 @@ int main(int argc, const char **argv) g.setDevice(device.str()); g.setScale(1); g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::VideoCapture cap(opt_device); // open the default camera if (!cap.isOpened()) { // check if we succeeded std::cout << "Failed to open the camera" << std::endl; @@ -91,7 +105,7 @@ int main(int argc, const char **argv) //! [Acquisition] #if defined(VISP_HAVE_V4L2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cap >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #endif @@ -129,8 +143,13 @@ int main(int argc, const char **argv) catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } +} + #else - (void)argc; - (void)argv; -#endif + +int main() +{ + std::cout << "There are missing 3rd parties to run this tutorial" << std::endl; } + +#endif diff --git a/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp b/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp index cbe4ddecf3..66a345465c 100644 --- a/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp +++ b/tutorial/detection/dnn/tutorial-dnn-object-detection-live.cpp @@ -1,14 +1,19 @@ //! \example tutorial-dnn-object-detection-live.cpp +#include + #include + + // Check if std:c++17 or higher +#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_VIDEOIO) && \ + ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + #include #include #include #include #include -#if defined(HAVE_OPENCV_VIDEOIO) #include -#endif #ifdef VISP_HAVE_NLOHMANN_JSON #include VISP_NLOHMANN_JSON(json.hpp) @@ -70,9 +75,6 @@ std::string getAvailableDetectionContainer() int main(int argc, const char *argv[]) { - // Check if std:c++17 or higher -#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_VIDEOIO) && \ - ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) try { std::string opt_device("0"); //! [OpenCV DNN face detector] @@ -455,9 +457,22 @@ int main(int argc, const char *argv[]) catch (const vpException &e) { std::cout << e.what() << std::endl; } +} + #else - (void)argc; - (void)argv; + +int main() +{ +#if !defined(HAVE_OPENCV_DNN) + std::cout << "This tutorial needs OpenCV dnn module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEOIO) + std::cout << "This tutorial needs OpenCV videoio module that is missing." << std::endl; +#endif +#if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) + std::cout << "This tutorial needs std::c++17 standard enabled." << std::endl; #endif return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/detection/dnn/tutorial-dnn-tensorrt-live.cpp b/tutorial/detection/dnn/tutorial-dnn-tensorrt-live.cpp index e5ba552623..6e62c43b2b 100644 --- a/tutorial/detection/dnn/tutorial-dnn-tensorrt-live.cpp +++ b/tutorial/detection/dnn/tutorial-dnn-tensorrt-live.cpp @@ -13,6 +13,7 @@ // #include + #include #if defined(VISP_HAVE_TENSORRT) && defined(VISP_HAVE_OPENCV) diff --git a/tutorial/detection/face/tutorial-face-detector-live-threaded.cpp b/tutorial/detection/face/tutorial-face-detector-live-threaded.cpp index 8474d631ff..88f3857b20 100644 --- a/tutorial/detection/face/tutorial-face-detector-live-threaded.cpp +++ b/tutorial/detection/face/tutorial-face-detector-live-threaded.cpp @@ -3,9 +3,16 @@ #include -#if defined(VISP_HAVE_THREADS) && defined(HAVE_OPENCV_HIGHGUI) \ - && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEOIO) \ - && (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_OBJDETECT)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XOBJDETECT))) +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if defined(VISP_HAVE_THREADS) && defined(HAVE_OPENCV_IMGPROC) \ + && (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_OBJDETECT)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XOBJDETECT))) \ + && (defined(VISP_HAVE_V4L2) || (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))) #include #include @@ -17,7 +24,11 @@ #include #include -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture +#endif #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; @@ -35,7 +46,7 @@ void captureFunction(cv::VideoCapture &cap, std::mutex &mutex_capture, cv::Mat & // If the image is larger than 640 by 480, we subsample #if defined(VISP_HAVE_V4L2) vpImage frame_; -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::Mat frame_; #endif bool stop_capture_ = false; @@ -65,7 +76,7 @@ void captureFunction(cv::VideoCapture &cap, std::mutex &mutex_capture, cv::Mat & #if defined(VISP_HAVE_V4L2) void displayFunction(std::mutex &mutex_capture, std::mutex &mutex_face, vpImage &frame, t_CaptureState &capture_state, vpRect &face_bbox, bool &face_available) -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) void displayFunction(std::mutex &mutex_capture, std::mutex &mutex_face, cv::Mat &frame, t_CaptureState &capture_state, vpRect &face_bbox, bool &face_available) #endif { @@ -94,7 +105,7 @@ void displayFunction(std::mutex &mutex_capture, std::mutex &mutex_face, cv::Mat std::lock_guard lock(mutex_capture); #if defined(VISP_HAVE_V4L2) I_ = frame; -#elif defined(VISP_HAVE_OPENCV) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) vpImageConvert::convert(frame, I_); #endif } @@ -152,7 +163,7 @@ void displayFunction(std::mutex &mutex_capture, std::mutex &mutex_face, cv::Mat //! [face-detection-threaded detectionFunction] #if defined(VISP_HAVE_V4L2) void detectionFunction(std::mutex &mutex_capture, std::mutex &mutex_face, vpImage &frame, t_CaptureState &capture_state, vpRect &face_bbox, std::string &face_cascade_name, bool &face_available) -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) void detectionFunction(std::mutex &mutex_capture, std::mutex &mutex_face, cv::Mat &frame, t_CaptureState &capture_state, vpRect &face_bbox, std::string &face_cascade_name, bool &face_available) #endif { @@ -162,7 +173,7 @@ void detectionFunction(std::mutex &mutex_capture, std::mutex &mutex_face, cv::Ma t_CaptureState capture_state_; #if defined(VISP_HAVE_V4L2) vpImage frame_; -#elif defined(VISP_HAVE_OPENCV) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::Mat frame_; #endif do { @@ -231,7 +242,7 @@ int main(int argc, const char *argv[]) device << "/dev/video" << opt_device; cap.setDevice(device.str()); cap.setScale(opt_scale); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::Mat frame; cv::VideoCapture cap; cap.open(opt_device); diff --git a/tutorial/detection/face/tutorial-face-detector-live.cpp b/tutorial/detection/face/tutorial-face-detector-live.cpp index ad899f7314..a3afa1633c 100644 --- a/tutorial/detection/face/tutorial-face-detector-live.cpp +++ b/tutorial/detection/face/tutorial-face-detector-live.cpp @@ -1,5 +1,19 @@ //! \example tutorial-face-detector-live.cpp +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if defined(HAVE_OPENCV_IMGPROC) \ + && (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_OBJDETECT)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XOBJDETECT))) \ + && (defined(VISP_HAVE_V4L2) || (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))) + #include #include #include @@ -8,14 +22,14 @@ #include #endif -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include #endif int main(int argc, const char *argv[]) { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) \ - && (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_OBJDETECT)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_XOBJDETECT))) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -57,7 +71,7 @@ int main(int argc, const char *argv[]) g.setScale(opt_scale); // Default value is 2 in the constructor. Turn it // to 1 to avoid subsampling g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cv::VideoCapture cap(opt_device); // open the default camera #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) int width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH); @@ -98,7 +112,7 @@ int main(int argc, const char *argv[]) #if defined(VISP_HAVE_V4L2) g.acquire(I); bool face_found = face_detector.detect(I); -#else +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cap >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); bool face_found = face_detector.detect(frame); // We pass frame to avoid an internal image conversion @@ -129,12 +143,12 @@ int main(int argc, const char *argv[]) catch (const vpException &e) { std::cout << e.getMessage() << std::endl; } -#else +} +#else -#if !defined(HAVE_OPENCV_HIGHGUI) - std::cout << "This tutorial needs OpenCV highgui module that is missing." << std::endl; -#endif +int main() +{ #if !defined(HAVE_OPENCV_IMGPROC) std::cout << "This tutorial needs OpenCV imgproc module that is missing." << std::endl; #endif @@ -144,8 +158,6 @@ int main(int argc, const char *argv[]) #if ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && !defined(HAVE_OPENCV_XOBJDETECT)) std::cout << "This tutorial needs OpenCV xobjdetect module that is missing." << std::endl; #endif +} - (void)argc; - (void)argv; #endif -} diff --git a/tutorial/detection/object/tutorial-detection-object-mbt2-deprecated.cpp b/tutorial/detection/object/tutorial-detection-object-mbt2-deprecated.cpp index 853b554160..78fc69cd81 100644 --- a/tutorial/detection/object/tutorial-detection-object-mbt2-deprecated.cpp +++ b/tutorial/detection/object/tutorial-detection-object-mbt2-deprecated.cpp @@ -128,10 +128,14 @@ int main(int argc, char **argv) //! [Keypoint declaration] vpKeyPoint keypoint_learning("ORB", "ORB", "BruteForce-Hamming"); #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) + keypoint_learning.setDetectorParameter("ORB", "nLevels", 1); +#else cv::Ptr orb_learning = keypoint_learning.getDetector("ORB").dynamicCast(); if (orb_learning) { orb_learning->setNLevels(1); } +#endif #endif //! [Keypoint declaration] @@ -204,11 +208,15 @@ int main(int argc, char **argv) //! [Init keypoint detection] vpKeyPoint keypoint_detection("ORB", "ORB", "BruteForce-Hamming"); #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) + keypoint_detection.setDetectorParameter("ORB", "nLevels", 1); +#else cv::Ptr orb_detector = keypoint_detection.getDetector("ORB").dynamicCast(); orb_detector = keypoint_detection.getDetector("ORB").dynamicCast(); if (orb_detector) { orb_detector->setNLevels(1); } +#endif #endif //! [Init keypoint detection] diff --git a/tutorial/detection/object/tutorial-detection-object-mbt2.cpp b/tutorial/detection/object/tutorial-detection-object-mbt2.cpp index 26daf57ca9..bcab8b2b03 100644 --- a/tutorial/detection/object/tutorial-detection-object-mbt2.cpp +++ b/tutorial/detection/object/tutorial-detection-object-mbt2.cpp @@ -129,10 +129,14 @@ int main(int argc, char **argv) //! [Keypoint declaration] vpKeyPoint keypoint_learning("ORB", "ORB", "BruteForce-Hamming"); #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) + keypoint_learning.setDetectorParameter("ORB", "nLevels", 1); +#else cv::Ptr orb_learning = keypoint_learning.getDetector("ORB").dynamicCast(); if (orb_learning) { orb_learning->setNLevels(1); } +#endif #endif //! [Keypoint declaration] @@ -205,11 +209,15 @@ int main(int argc, char **argv) //! [Init keypoint detection] vpKeyPoint keypoint_detection("ORB", "ORB", "BruteForce-Hamming"); #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) + keypoint_detection.setDetectorParameter("ORB", "nLevels", 1); +#else cv::Ptr orb_detector = keypoint_detection.getDetector("ORB").dynamicCast(); orb_detector = keypoint_detection.getDetector("ORB").dynamicCast(); if (orb_detector) { orb_detector->setNLevels(1); } +#endif #endif //! [Init keypoint detection] diff --git a/tutorial/detection/tag/tutorial-apriltag-detector-live.cpp b/tutorial/detection/tag/tutorial-apriltag-detector-live.cpp index c63f63d9c6..277d3ca75a 100644 --- a/tutorial/detection/tag/tutorial-apriltag-detector-live.cpp +++ b/tutorial/detection/tag/tutorial-apriltag-detector-live.cpp @@ -1,5 +1,28 @@ //! \example tutorial-apriltag-detector-live.cpp +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +//! [Macro defined] +#if defined(VISP_HAVE_APRILTAG) && \ + (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ + defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + +//! [Macro defined] + #ifdef VISP_HAVE_MODULE_SENSOR #include #include @@ -15,27 +38,14 @@ #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include #endif -//! [Undef grabber] -// #undef VISP_HAVE_V4L2 -// #undef VISP_HAVE_DC1394 -// #undef VISP_HAVE_CMU1394 -// #undef VISP_HAVE_FLYCAPTURE -// #undef VISP_HAVE_REALSENSE2 -// #undef VISP_HAVE_OPENCV -//! [Undef grabber] - int main(int argc, const char **argv) { - //! [Macro defined] -#if defined(VISP_HAVE_APRILTAG) && \ - (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ - defined(HAVE_OPENCV_VIDEOIO) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2)) - //! [Macro defined] - #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -170,7 +180,7 @@ int main(int argc, const char **argv) std::cout << "Read camera parameters from Realsense device" << std::endl; cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; cv::VideoCapture g(opt_device); // Open the default camera if (!g.isOpened()) { // Check if we succeeded @@ -218,7 +228,7 @@ int main(int argc, const char **argv) #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -264,16 +274,20 @@ int main(int argc, const char **argv) } return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; + +int main() +{ #ifndef VISP_HAVE_APRILTAG std::cout << "Enable Apriltag support, configure and build ViSP to run this tutorial" << std::endl; #else std::cout << "Install a 3rd party dedicated to frame grabbing (dc1394, cmu1394, v4l2, OpenCV, FlyCapture, " - "Realsense2), configure and build ViSP again to use this example" + << "Realsense2), configure and build ViSP again to use this example" << std::endl; -#endif #endif return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/grabber/tutorial-grabber-opencv-threaded.cpp b/tutorial/grabber/tutorial-grabber-opencv-threaded.cpp index 9f035ce720..5e1b29f3ef 100644 --- a/tutorial/grabber/tutorial-grabber-opencv-threaded.cpp +++ b/tutorial/grabber/tutorial-grabber-opencv-threaded.cpp @@ -3,18 +3,23 @@ #include #include -#include -#include -#include -#include -#if defined(HAVE_OPENCV_VIDEOIO) && defined(VISP_HAVE_THREADS) +#if defined(VISP_HAVE_THREADS) && \ + (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) #include #include -#include -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture +#endif + +#include +#include +#include +#include #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; @@ -168,11 +173,17 @@ int main(int argc, const char *argv[]) #else int main() { -#ifndef VISP_HAVE_OPENCV - std::cout << "You should install OpenCV videoio module to make this example working..." << std::endl; -#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX - std::cout << "You should enable pthread usage and rebuild ViSP..." << std::endl; -#else +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "Install OpenCV highgui module, configure and build ViSP again to use this tutorial." << std::endl; +#endif +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && !defined(HAVE_OPENCV_VIDEOIO) + std::cout << "Install OpenCV videoio module, configure and build ViSP again to use this tutorial." << std::endl; +#endif +#if !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "Install OpenCV highgui module, configure and build ViSP again to use this tutorial." << std::endl; +#endif +#if !defined(VISP_HAVE_THREADS) // UNIX + std::cout << "This tutorial cannot run without std::thread usage." << std::endl; std::cout << "Multi-threading seems not supported on this platform" << std::endl; #endif return EXIT_SUCCESS; diff --git a/tutorial/grabber/tutorial-grabber-opencv.cpp b/tutorial/grabber/tutorial-grabber-opencv.cpp index 8efe63c868..129855bb61 100644 --- a/tutorial/grabber/tutorial-grabber-opencv.cpp +++ b/tutorial/grabber/tutorial-grabber-opencv.cpp @@ -1,14 +1,21 @@ /*! \example tutorial-grabber-opencv.cpp */ -#include +#include + #include -#include -#include -#include + +#if defined(HAVE_OPENCV_HIGHGUI) && \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) #if defined(HAVE_OPENCV_VIDEOIO) #include #endif +#include + +#include +#include +#include + #define USE_COLOR // Comment to acquire gray level images void usage(const char *argv[], int error) @@ -119,7 +126,6 @@ int main(int argc, const char *argv[]) std::cout << "Record name: " << opt_seqname << std::endl; } -#if defined(HAVE_OPENCV_VIDEOIO) && defined(HAVE_OPENCV_HIGHGUI) && defined(VISP_HAVE_THREADS) try { cv::VideoCapture cap(opt_device); // open the default camera if (!cap.isOpened()) { // check if we succeeded @@ -181,14 +187,15 @@ int main(int argc, const char *argv[]) catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } +} #else - (void)argc; - (void)argv; -#if !defined(HAVE_OPENCV_VIDEOIO) - std::cout << "Install OpenCV videoio module, configure and build ViSP again to use this example" << std::endl; -#endif -#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11) - std::cout << "This tutorial should be built with c++11 support" << std::endl; +int main() +{ +#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && !defined(HAVE_OPENCV_VIDEOIO) + std::cout << "Install OpenCV videoio module, configure and build ViSP again to use this tutorial." << std::endl; #endif +#if !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "Install OpenCV highgui module, configure and build ViSP again to use this tutorial." << std::endl; #endif } +#endif diff --git a/tutorial/grabber/tutorial-video-reader.cpp b/tutorial/grabber/tutorial-video-reader.cpp index 1949126ff9..b4e14d7c0c 100644 --- a/tutorial/grabber/tutorial-video-reader.cpp +++ b/tutorial/grabber/tutorial-video-reader.cpp @@ -14,7 +14,7 @@ */ int main(int argc, char **argv) { -#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) +#if ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif diff --git a/tutorial/grabber/tutorial-video-recorder.cpp b/tutorial/grabber/tutorial-video-recorder.cpp index 80d992ca44..abfb4b26dc 100644 --- a/tutorial/grabber/tutorial-video-recorder.cpp +++ b/tutorial/grabber/tutorial-video-recorder.cpp @@ -1,13 +1,29 @@ /*! \example tutorial-video-recorder.cpp */ +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +#undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if defined(VISP_HAVE_DISPLAY) && \ + (defined(VISP_HAVE_V4L2) || \ + (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))) + #include #include #include #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif /*! @@ -29,7 +45,6 @@ */ int main(int argc, const char *argv[]) { -#if (defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && defined(VISP_HAVE_DISPLAY) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -67,7 +82,7 @@ int main(int argc, const char *argv[]) g.setScale(1); // Acquire full resolution images g.open(I); g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) std::cout << "Use OpenCV grabber..." << std::endl; cv::VideoCapture g(opt_device); if (!g.isOpened()) { // check if we succeeded @@ -101,7 +116,7 @@ int main(int argc, const char *argv[]) for (;;) { #if defined(VISP_HAVE_V4L2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -128,10 +143,21 @@ int main(int argc, const char *argv[]) catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } + return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; - std::cout << "Install OpenCV and rebuild ViSP to use this example." << std::endl; + +int main() +{ +#if !defined(VISP_HAVE_DISPLAY) + std::cout << "Install a 3rdparty to enable display feature (X11, GDI...) and rebuild ViSP to use this tutorial." << std::endl; +#endif +#if !(defined(VISP_HAVE_V4L2) || \ + (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))) + std::cout << "Install V4l2 or OpenCV 3rdparty and rebuild ViSP to use this tutorial." << std::endl; #endif - return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/segmentation/color/tutorial-hsv-range-tuner.cpp b/tutorial/segmentation/color/tutorial-hsv-range-tuner.cpp index 7b3e371cb2..a48308eb26 100644 --- a/tutorial/segmentation/color/tutorial-hsv-range-tuner.cpp +++ b/tutorial/segmentation/color/tutorial-hsv-range-tuner.cpp @@ -7,7 +7,7 @@ #if defined(HAVE_OPENCV_HIGHGUI) && defined(VISP_HAVE_X11) #include -#include +#include #include #include diff --git a/tutorial/tracking/blob/CMakeLists.txt b/tutorial/tracking/blob/CMakeLists.txt index 75e77c3cea..db78b10c5d 100644 --- a/tutorial/tracking/blob/CMakeLists.txt +++ b/tutorial/tracking/blob/CMakeLists.txt @@ -7,8 +7,7 @@ find_package(VISP REQUIRED visp_core visp_blob visp_io visp_gui visp_sensor) # set the list of source files set(tutorial_cpp tutorial-blob-auto-tracker.cpp - tutorial-blob-tracker-live-firewire.cpp - tutorial-blob-tracker-live-v4l2.cpp) + tutorial-blob-tracker-live.cpp) list(APPEND tutorial_data "${CMAKE_CURRENT_SOURCE_DIR}/target.pgm" ) diff --git a/tutorial/tracking/blob/tutorial-blob-tracker-live-firewire.cpp b/tutorial/tracking/blob/tutorial-blob-tracker-live-firewire.cpp deleted file mode 100644 index 1220d334c6..0000000000 --- a/tutorial/tracking/blob/tutorial-blob-tracker-live-firewire.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//! \example tutorial-blob-tracker-live-firewire.cpp -#include -#ifdef VISP_HAVE_MODULE_SENSOR -#include -#include -#endif -#include -#include -#include -#include - -#if defined(HAVE_OPENCV_VIDEOIO) -#include -#endif - -int main() -{ -#if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(HAVE_OPENCV_VIDEOIO)) && \ - (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) -#ifdef ENABLE_VISP_NAMESPACE - using namespace VISP_NAMESPACE_NAME; -#endif - - vpImage I; // Create a gray level image container - -#if defined(VISP_HAVE_DC1394) - vp1394TwoGrabber g(false); - g.open(I); -#elif defined(VISP_HAVE_CMU1394) - vp1394CMUGrabber g; - g.open(I); -#elif defined(HAVE_OPENCV_VIDEOIO) - cv::VideoCapture g(0); // open the default camera - if (!g.isOpened()) { // check if we succeeded - std::cout << "Failed to open the camera" << std::endl; - return EXIT_FAILURE; - } - cv::Mat frame; - g >> frame; // get a new frame from camera - vpImageConvert::convert(frame, I); -#endif - -#if defined(VISP_HAVE_X11) - vpDisplayX d(I, 0, 0, "Camera view"); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I, 0, 0, "Camera view"); -#elif defined(HAVE_OPENCV_HIGHGUI) - vpDisplayOpenCV d(I, 0, 0, "Camera view"); -#endif - - //! [Construction] - vpDot2 blob; - //! [Construction] - //! [Setting] - blob.setGraphics(true); - blob.setGraphicsThickness(2); - //! [Setting] - - vpImagePoint germ; - bool init_done = false; - - while (1) { - try { -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) - g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) - g >> frame; - vpImageConvert::convert(frame, I); -#endif - vpDisplay::display(I); - - if (!init_done) { - vpDisplay::displayText(I, vpImagePoint(10, 10), "Click in the blob to initialize the tracker", vpColor::red); - if (vpDisplay::getClick(I, germ, false)) { - //! [Init] - blob.initTracking(I, germ); - //! [Init] - init_done = true; - } - } - else { - //! [Track] - blob.track(I); - //! [Track] - } - - vpDisplay::flush(I); - } - catch (...) { - init_done = false; - } -} -#endif -} diff --git a/tutorial/tracking/blob/tutorial-blob-tracker-live-v4l2.cpp b/tutorial/tracking/blob/tutorial-blob-tracker-live-v4l2.cpp deleted file mode 100644 index f8de05b3f1..0000000000 --- a/tutorial/tracking/blob/tutorial-blob-tracker-live-v4l2.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//! \example tutorial-blob-tracker-live-v4l2.cpp -#include -#ifdef VISP_HAVE_MODULE_SENSOR -#include -#endif -#include -#include -#include -#include -#include - -#if defined(HAVE_OPENCV_VIDEOIO) -#include -#endif - -int main(int argc, char **argv) -{ -#if ((defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && \ - (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK))) - -#ifdef ENABLE_VISP_NAMESPACE - using namespace VISP_NAMESPACE_NAME; -#endif - - int device = 0; - if (argc == 2) { - device = std::atoi(argv[1]); - } - vpImage I; // Create a gray level image container - - std::stringstream ss; - ss << "/dev/video" << device; - - std::cout << "Connect to: " << ss.str() << std::endl; -#if defined(VISP_HAVE_V4L2) - vpV4l2Grabber g; - g.setDevice(ss.str()); - g.open(I); -#elif defined(HAVE_OPENCV_VIDEOIO) - cv::VideoCapture g(device); // open the default camera - if (!g.isOpened()) { // check if we succeeded - std::cout << "Failed to open the camera" << std::endl; - return EXIT_FAILURE; - } - cv::Mat frame; - g >> frame; // get a new frame from camera - vpImageConvert::convert(frame, I); -#endif - -#if defined(VISP_HAVE_X11) - vpDisplayX d(I, 0, 0, "Camera view"); -#elif defined(VISP_HAVE_GDI) - vpDisplayGDI d(I, 0, 0, "Camera view"); -#elif defined(HAVE_OPENCV_HIGHGUI) - vpDisplayOpenCV d(I, 0, 0, "Camera view"); -#elif defined(VISP_HAVE_GTK) - vpDisplayGTK d(I, 0, 0, "Camera view"); -#endif - - vpDot2 blob; - blob.setGraphics(true); - blob.setGraphicsThickness(2); - - vpImagePoint germ; - bool init_done = false; - std::cout << "Click!!!" << std::endl; - while (1) { - try { -#if defined(VISP_HAVE_V4L2) - g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) - g >> frame; - vpImageConvert::convert(frame, I); -#endif - vpDisplay::display(I); - - if (!init_done) { - vpDisplay::displayText(I, vpImagePoint(10, 10), "Click in the blob to initialize the tracker", vpColor::red); - if (vpDisplay::getClick(I, germ, false)) { - blob.initTracking(I, germ); - init_done = true; - } - } - else { - blob.track(I); - } - vpDisplay::flush(I); - } - catch (...) { - init_done = false; - } - } -#else - (void)argc; - (void)argv; -#endif -} diff --git a/tutorial/tracking/blob/tutorial-blob-tracker-live.cpp b/tutorial/tracking/blob/tutorial-blob-tracker-live.cpp new file mode 100644 index 0000000000..7071741a6d --- /dev/null +++ b/tutorial/tracking/blob/tutorial-blob-tracker-live.cpp @@ -0,0 +1,167 @@ +//! \example tutorial-blob-tracker-live.cpp +#include + +#include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && \ + (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ + defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + +#ifdef VISP_HAVE_MODULE_SENSOR +#include +#include +#include +#include +#include +#endif +#include +#include +#include +#include + +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include +#endif + +int main() +{ +#ifdef ENABLE_VISP_NAMESPACE + using namespace VISP_NAMESPACE_NAME; +#endif + + vpImage I; // Create a gray level image container + int opt_device = 0; // For OpenCV and V4l2 grabber to set the camera device + + //! [Grabber] +#if defined(VISP_HAVE_V4L2) + vpV4l2Grabber g; + std::ostringstream device; + device << "/dev/video" << opt_device; + std::cout << "Use Video 4 Linux grabber on device " << device.str() << std::endl; + g.setDevice(device.str()); + g.setScale(1); + g.open(I); +#elif defined(VISP_HAVE_DC1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use DC1394 grabber" << std::endl; + vp1394TwoGrabber g; + g.open(I); +#elif defined(VISP_HAVE_CMU1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use CMU1394 grabber" << std::endl; + vp1394CMUGrabber g; + g.open(I); +#elif defined(VISP_HAVE_FLYCAPTURE) + (void)opt_device; // To avoid non used warning + std::cout << "Use FlyCapture grabber" << std::endl; + vpFlyCaptureGrabber g; + g.open(I); +#elif defined(VISP_HAVE_REALSENSE2) + (void)opt_device; // To avoid non used warning + std::cout << "Use Realsense 2 grabber" << std::endl; + vpRealSense2 g; + rs2::config config; + config.disable_stream(RS2_STREAM_DEPTH); + config.disable_stream(RS2_STREAM_INFRARED); + config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); + g.open(config); + g.acquire(I); + + std::cout << "Read camera parameters from Realsense device" << std::endl; + cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + cv::VideoCapture g(opt_device); // open the default camera + if (!g.isOpened()) { // check if we succeeded + std::cout << "Failed to open the camera" << std::endl; + return EXIT_FAILURE; + } + cv::Mat frame; + g >> frame; // get a new frame from camera + vpImageConvert::convert(frame, I); +#endif + +#if defined(VISP_HAVE_X11) + vpDisplayX d(I, 0, 0, "Camera view"); +#elif defined(VISP_HAVE_GDI) + vpDisplayGDI d(I, 0, 0, "Camera view"); +#elif defined(HAVE_OPENCV_HIGHGUI) + vpDisplayOpenCV d(I, 0, 0, "Camera view"); +#endif + + //! [Construction] + vpDot2 blob; + //! [Construction] + //! [Setting] + blob.setGraphics(true); + blob.setGraphicsThickness(2); + //! [Setting] + + vpImagePoint germ; + bool init_done = false; + bool quit = false; + bool germ_selected = false; + vpMouseButton::vpMouseButtonType button; + + while (! quit) { + try { +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) + g.acquire(I); +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + g >> frame; + vpImageConvert::convert(frame, I); +#endif + vpDisplay::display(I); + vpDisplay::displayText(I, 20, 20, "Left click in the blob to initialize the tracker", vpColor::red); + vpDisplay::displayText(I, 40, 20, "Right click to quit", vpColor::red); + + if (vpDisplay::getClick(I, germ, button, false)) { + if (button == vpMouseButton::button3) { + quit = true; + } + else { + germ_selected = true; + } + } + if (germ_selected && !init_done) { + //! [Init] + std::cout << "Tracking initialized" << std::endl; + blob.initTracking(I, germ); + //! [Init] + init_done = true; + germ_selected = false; + } + else if (init_done) { + //! [Track] + blob.track(I); + //! [Track] + } + + vpDisplay::flush(I); + } + catch (const vpException &e) { + std::cout << "Tracking failed: " << e.getMessage() << std::endl; + init_done = false; + } + } +} + +#else +int main() +{ + std::cout << "There are missing 3rd parties to run this tutorial" << std::endl; +} +#endif diff --git a/tutorial/tracking/keypoint/CMakeLists.txt b/tutorial/tracking/keypoint/CMakeLists.txt index 21d12078e2..a5e8e1612b 100644 --- a/tutorial/tracking/keypoint/CMakeLists.txt +++ b/tutorial/tracking/keypoint/CMakeLists.txt @@ -7,7 +7,7 @@ find_package(VISP REQUIRED visp_core visp_vision visp_klt visp_io visp_gui visp_ # set the list of source files set(tutorial_cpp tutorial-klt-tracker.cpp - tutorial-klt-tracker-live-v4l2.cpp + tutorial-klt-tracker-live.cpp tutorial-klt-tracker-with-reinit.cpp) list(APPEND tutorial_data "${CMAKE_CURRENT_SOURCE_DIR}/video-postcard.mp4" ) diff --git a/tutorial/tracking/keypoint/tutorial-klt-tracker-live-v4l2.cpp b/tutorial/tracking/keypoint/tutorial-klt-tracker-live.cpp similarity index 63% rename from tutorial/tracking/keypoint/tutorial-klt-tracker-live-v4l2.cpp rename to tutorial/tracking/keypoint/tutorial-klt-tracker-live.cpp index 8c2a9c8a51..3cf12e8df9 100644 --- a/tutorial/tracking/keypoint/tutorial-klt-tracker-live-v4l2.cpp +++ b/tutorial/tracking/keypoint/tutorial-klt-tracker-live.cpp @@ -1,5 +1,19 @@ -/*! \example tutorial-klt-tracker-live-v4l2.cpp */ +/*! \example tutorial-klt-tracker-live.cpp */ +#include + #include + +//! [Undef grabber] +// Comment / uncomment following lines to use the specific 3rd party compatible with your camera +// #undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && \ + (defined(VISP_HAVE_V4L2) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + #ifdef VISP_HAVE_MODULE_SENSOR #include #endif @@ -8,13 +22,14 @@ #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include #endif int main(int argc, const char *argv[]) { -#if (defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) || defined(VISP_HAVE_V4L2)) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -39,13 +54,15 @@ int main(int argc, const char *argv[]) vpImage I; #if defined(VISP_HAVE_V4L2) + std::cout << "Use v4l2 grabber..." << std::endl; vpV4l2Grabber g; std::ostringstream device; device << "/dev/video" << opt_device; g.setDevice(device.str()); g.open(I); g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + std::cout << "Use OpenCV grabber..." << std::endl; cv::VideoCapture g(opt_device); if (!g.isOpened()) { // check if we succeeded std::cout << "Failed to open the camera" << std::endl; @@ -101,7 +118,7 @@ int main(int argc, const char *argv[]) while (1) { #if defined(VISP_HAVE_V4L2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -121,9 +138,26 @@ int main(int argc, const char *argv[]) std::cout << "Catch an exception: " << e << std::endl; return EXIT_FAILURE; } + return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; + +int main() +{ +#if !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "This tutorial needs OpenCV highgui module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_IMGPROC) + std::cout << "This tutorial needs OpenCV imgproc module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEO) + std::cout << "This tutorial needs OpenCV video module that is missing." << std::endl; +#endif +#if !(defined(VISP_HAVE_V4L2) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + std::cout << "This tutorial needs V4l2 or OpenCV grabber capabilities." << std::endl; #endif - return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/tracking/keypoint/tutorial-klt-tracker-with-reinit.cpp b/tutorial/tracking/keypoint/tutorial-klt-tracker-with-reinit.cpp index 28ebb2117d..5c331cccf1 100644 --- a/tutorial/tracking/keypoint/tutorial-klt-tracker-with-reinit.cpp +++ b/tutorial/tracking/keypoint/tutorial-klt-tracker-with-reinit.cpp @@ -1,5 +1,10 @@ //! \example tutorial-klt-tracker-with-reinit.cpp +#include + #include + +#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && defined(HAVE_OPENCV_VIDEOIO) + #include #include #include @@ -7,7 +12,6 @@ int main() { -#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && defined(HAVE_OPENCV_VIDEOIO) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -100,6 +104,25 @@ int main() std::cout << "Catch an exception: " << e << std::endl; return EXIT_FAILURE; } -#endif return EXIT_SUCCESS; } + +#else + +int main() +{ +#if !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "This tutorial needs OpenCV highgui module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_IMGPROC) + std::cout << "This tutorial needs OpenCV imgproc module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEO) + std::cout << "This tutorial needs OpenCV video module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEOIO) + std::cout << "This tutorial needs OpenCV videoio module that is missing." << std::endl; +#endif +} + +#endif diff --git a/tutorial/tracking/keypoint/tutorial-klt-tracker.cpp b/tutorial/tracking/keypoint/tutorial-klt-tracker.cpp index 0f7e247c35..9c24cdb8ae 100644 --- a/tutorial/tracking/keypoint/tutorial-klt-tracker.cpp +++ b/tutorial/tracking/keypoint/tutorial-klt-tracker.cpp @@ -1,6 +1,13 @@ //! \example tutorial-klt-tracker.cpp -//! [Include] +#include + #include + +//! [Check 3rd party] +#if defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && defined(HAVE_OPENCV_VIDEOIO) +//! [Check 3rd party] + +//! [Include] #include #include #include @@ -9,9 +16,6 @@ int main(int argc, const char *argv[]) { -//! [Check 3rd party] -#if (defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_VIDEOIO) || defined(VISP_HAVE_V4L2)) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) - //! [Check 3rd party] #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -93,7 +97,7 @@ int main(int argc, const char *argv[]) tracker.initTracking(cvI, feature); } else { - //! [Init tracker] + //! [Init tracker] tracker.initTracking(cvI); //! [Init tracker] } @@ -152,9 +156,25 @@ int main(int argc, const char *argv[]) std::cout << "Catch an exception: " << e << std::endl; return EXIT_FAILURE; } + return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; + +int main() +{ +#if !defined(HAVE_OPENCV_HIGHGUI) + std::cout << "This tutorial needs OpenCV highgui module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_IMGPROC) + std::cout << "This tutorial needs OpenCV imgproc module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEO) + std::cout << "This tutorial needs OpenCV video module that is missing." << std::endl; +#endif +#if !defined(HAVE_OPENCV_VIDEOIO) + std::cout << "This tutorial needs OpenCV videoio module that is missing." << std::endl; #endif - return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-rs2.cpp b/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-rs2.cpp index 6a4034b21c..c9de6f3343 100644 --- a/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-rs2.cpp +++ b/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-rs2.cpp @@ -1,9 +1,16 @@ //! \example tutorial-mb-generic-tracker-apriltag-rs2.cpp -#include -#include + #include #include + +//! [Macro defined] +#if defined(VISP_HAVE_APRILTAG) && defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_MODULE_MBT) +//! [Macro defined] + +#include +#include + #include #include #include @@ -53,9 +60,8 @@ void createCaoFile(double cubeEdgeSize) fileStream.close(); } -#if defined(VISP_HAVE_APRILTAG) state_t detectAprilTag(const vpImage &I, vpDetectorAprilTag &detector, double tagSize, - const vpCameraParameters &cam, vpHomogeneousMatrix &cMo) + const vpCameraParameters &cam, vpHomogeneousMatrix &cMo) { std::vector cMo_vec; @@ -76,10 +82,9 @@ state_t detectAprilTag(const vpImage &I, vpDetectorAprilTag &dete return state_detection; } -#endif // #if defined(VISP_HAVE_APRILTAG) state_t track(const vpImage &I, vpMbGenericTracker &tracker, double projection_error_threshold, - vpHomogeneousMatrix &cMo) + vpHomogeneousMatrix &cMo) { vpCameraParameters cam; tracker.getCameraParameters(cam); @@ -157,10 +162,6 @@ state_t track(std::map *> mapOfImages, int main(int argc, const char **argv) { - //! [Macro defined] -#if defined(VISP_HAVE_APRILTAG) && defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_MODULE_MBT) - //! [Macro defined] - vpDetectorAprilTag::vpAprilTagFamily opt_tag_family = vpDetectorAprilTag::TAG_36h11; double opt_tag_size = 0.08; float opt_quad_decimate = 1.0; @@ -194,7 +195,7 @@ int main(int argc, const char **argv) else if (std::string(argv[i]) == "--tag-family" && i + 1 < argc) { opt_tag_family = (vpDetectorAprilTag::vpAprilTagFamily)atoi(argv[i + 1]); } - else if (std::string(argv[i]) == "--cube_size" && i + 1 < argc) { + else if (std::string(argv[i]) == "--cube-size" && i + 1 < argc) { opt_cube_size = atof(argv[i + 1]); #ifdef VISP_HAVE_OPENCV } @@ -205,19 +206,23 @@ int main(int argc, const char **argv) else if (std::string(argv[i]) == "--depth") { opt_use_depth = true; } - else if (std::string(argv[i]) == "--projection_error" && i + 1 < argc) { + else if (std::string(argv[i]) == "--projection-error" && i + 1 < argc) { opt_projection_error_threshold = atof(argv[i + 1]); } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { std::cout << "Usage: " << argv[0] - << " [--cube_size ] [--tag-size ]" - " [--quad-decimate ] [--nthreads ]" - " [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, " - " 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>]"; + << " [--cube-size ]" + << " [--tag-size ]" + << " [--quad-decimate ]" + << " [--nthreads ]" + << " [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>]"; #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) std::cout << " [--display-off]"; #endif - std::cout << " [--texture] [--depth] [--projection_error <30 - 100>] [--help]" << std::endl; + std::cout << " [--texture]" + << " [--depth]" + << " [--projection-error <30 - 100>]" + << " [--help,h]" << std::endl; return EXIT_SUCCESS; } } @@ -462,9 +467,12 @@ int main(int argc, const char **argv) } return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; + +int main() +{ #ifndef VISP_HAVE_APRILTAG std::cout << "ViSP is not build with Apriltag support" << std::endl; #endif @@ -472,6 +480,8 @@ int main(int argc, const char **argv) std::cout << "ViSP is not build with librealsense2 support" << std::endl; #endif std::cout << "Install missing 3rd parties, configure and build ViSP to run this tutorial" << std::endl; -#endif + return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-webcam.cpp b/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-webcam.cpp index da7bf2957a..e67e466c00 100644 --- a/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-webcam.cpp +++ b/tutorial/tracking/model-based/generic-apriltag/tutorial-mb-generic-tracker-apriltag-webcam.cpp @@ -1,19 +1,38 @@ //! \example tutorial-mb-generic-tracker-apriltag-webcam.cpp -#include -#include #include #include + +//! [Undef grabber] +// #undef VISP_HAVE_V4L2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +//! [Macro defined] +#if defined(VISP_HAVE_APRILTAG) && defined(VISP_HAVE_MODULE_MBT) && \ + (defined(VISP_HAVE_V4L2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) +//! [Macro defined] + +#include +#include + +#ifdef VISP_HAVE_MODULE_SENSOR +#include +#endif #include #include #include #include #include #include -#include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif #ifdef ENABLE_VISP_NAMESPACE @@ -58,9 +77,8 @@ void createCaoFile(double cubeEdgeSize) fileStream.close(); } -#if defined(VISP_HAVE_APRILTAG) state_t detectAprilTag(const vpImage &I, vpDetectorAprilTag &detector, double tagSize, - const vpCameraParameters &cam, vpHomogeneousMatrix &cMo) + const vpCameraParameters &cam, vpHomogeneousMatrix &cMo) { std::vector cMo_vec; @@ -81,10 +99,9 @@ state_t detectAprilTag(const vpImage &I, vpDetectorAprilTag &dete return state_detection; } -#endif // #if defined(VISP_HAVE_APRILTAG) state_t track(const vpImage &I, vpMbGenericTracker &tracker, double projection_error_threshold, - vpHomogeneousMatrix &cMo) + vpHomogeneousMatrix &cMo) { vpCameraParameters cam; tracker.getCameraParameters(cam); @@ -120,10 +137,6 @@ state_t track(const vpImage &I, vpMbGenericTracker &tracker, doub int main(int argc, const char **argv) { - //! [Macro defined] -#if defined(VISP_HAVE_APRILTAG) && (defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && defined(VISP_HAVE_MODULE_MBT) - //! [Macro defined] - int opt_device = 0; vpDetectorAprilTag::vpAprilTagFamily opt_tag_family = vpDetectorAprilTag::TAG_36h11; double opt_tag_size = 0.08; @@ -168,7 +181,7 @@ int main(int argc, const char **argv) else if (std::string(argv[i]) == "--tag-family" && i + 1 < argc) { opt_tag_family = (vpDetectorAprilTag::vpAprilTagFamily)atoi(argv[i + 1]); } - else if (std::string(argv[i]) == "--cube_size" && i + 1 < argc) { + else if (std::string(argv[i]) == "--cube-size" && i + 1 < argc) { opt_cube_size = atof(argv[i + 1]); #ifdef VISP_HAVE_OPENCV } @@ -176,20 +189,25 @@ int main(int argc, const char **argv) opt_use_texture = true; #endif } - else if (std::string(argv[i]) == "--projection_error" && i + 1 < argc) { + else if (std::string(argv[i]) == "--projection-error" && i + 1 < argc) { opt_projection_error_threshold = atof(argv[i + 1]); } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") { std::cout << "Usage: " << argv[0] - << " [--input ] [--cube_size ] [--tag-size ]" - " [--quad-decimate ] [--nthreads ]" - " [--intrinsic ] [--camera-name ]" - " [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, " - " 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>]"; + << " [--input ]" + << " [--cube-size ]" + << " [--tag-size ]" + << " [--quad-decimate ]" + << " [--nthreads ]" + << " [--intrinsic ]" + << " [--camera-name ]" + << " [--tag-family <0: TAG_36h11, 1: TAG_36h10, 2: TAG_36ARTOOLKIT, 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5>]"; #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) std::cout << " [--display-off]"; #endif - std::cout << " [--texture] [--projection_error <30 - 100>] [--help]" << std::endl; + std::cout << " [--texture]" + << " [--projection-error <30 - 100>]" + << " [--help,-h]" << std::endl; return EXIT_SUCCESS; } } @@ -214,21 +232,22 @@ int main(int argc, const char **argv) vpV4l2Grabber g; std::ostringstream device; device << "/dev/video" << opt_device; - std::cout << "Use device " << device.str() << " (v4l2 grabber)" << std::endl; + std::cout << "Use Video 4 Linux grabber on device " << device.str() << std::endl; g.setDevice(device.str()); g.setScale(1); - g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) - std::cout << "Use device " << opt_device << " (OpenCV grabber)" << std::endl; - cv::VideoCapture cap(opt_device); // open the default camera - if (!cap.isOpened()) { // check if we succeeded + g.open(I); +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; + cv::VideoCapture g(opt_device); // Open the default camera + if (!g.isOpened()) { // Check if we succeeded std::cout << "Failed to open the camera" << std::endl; return EXIT_FAILURE; } cv::Mat frame; - cap >> frame; // get a new frame from camera + g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #endif + //! [Construct grabber] if (!camIsInit) { cam.initPersProjWithoutDistortion(600, 600, I.getWidth() / 2., I.getHeight() / 2.); } @@ -318,7 +337,7 @@ int main(int argc, const char **argv) #if defined(VISP_HAVE_V4L2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) cap >> frame; vpImageConvert::convert(frame, I); #endif @@ -356,16 +375,22 @@ int main(int argc, const char **argv) } return EXIT_SUCCESS; +} + #else - (void)argc; - (void)argv; -#ifndef VISP_HAVE_APRILTAG + +int main() +{ +#if !defined(VISP_HAVE_APRILTAG) std::cout << "ViSP is not build with Apriltag support" << std::endl; #endif #if !(defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_OPENCV)) std::cout << "ViSP is not build with v4l2 or OpenCV support" << std::endl; -#endif +#else std::cout << "Install missing 3rd parties, configure and build ViSP to run this tutorial" << std::endl; #endif + return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-live.cpp b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-live.cpp index 7e35a3ab91..3914636d98 100644 --- a/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-live.cpp +++ b/tutorial/tracking/model-based/generic/tutorial-mb-generic-tracker-live.cpp @@ -1,5 +1,25 @@ //! \example tutorial-mb-generic-tracker-live.cpp +#include + #include + +//! [Undef grabber] +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ + defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) && \ + ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES)) + #ifdef VISP_HAVE_MODULE_SENSOR #include #include @@ -18,27 +38,14 @@ #include //! [Include] -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif -//! [Undef grabber] -// #undef VISP_HAVE_V4L2 -// #undef VISP_HAVE_DC1394 -// #undef VISP_HAVE_CMU1394 -// #undef VISP_HAVE_FLYCAPTURE -// #undef VISP_HAVE_REALSENSE2 -// #undef VISP_HAVE_OPENCV -//! [Undef grabber] - int main(int argc, char **argv) { -#if defined(HAVE_OPENCV_VIDEOIO) && \ - (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ - defined(HAVE_OPENCV_HIGHGUI) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2)) && \ - ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \ - ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES)) - #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -103,7 +110,9 @@ int main(int argc, char **argv) << " [--tracker <0=egde|1=keypoint|2=hybrid> (default: 2)]" << " [--use_ogre] [--use_scanline]" << " [--max_proj_error (default: 30)]" - << " [--learn] [--auto_init] [--learning_data (default: learning/data-learned.bin)]" + << " [--learn]" + << " [--auto_init]" + << " [--learning_data (default: learning/data-learned.bin)]" << " [--display_proj_error]" << " [--help] [-h]\n" << std::endl; @@ -162,7 +171,7 @@ int main(int argc, char **argv) } #endif -//! [cMo] + //! [cMo] vpHomogeneousMatrix cMo; //! [cMo] @@ -203,7 +212,7 @@ int main(int argc, char **argv) std::cout << "Read camera parameters from Realsense device" << std::endl; cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; cv::VideoCapture g(opt_device); // Open the default camera if (!g.isOpened()) { // Check if we succeeded @@ -227,10 +236,9 @@ int main(int argc, char **argv) display->init(I, 100, 100, "Model-based tracker"); while (true) { -#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ - defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -346,10 +354,14 @@ int main(int argc, char **argv) keypoint.setExtractor(extractorName); keypoint.setMatcher(matcherName); #if ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_FEATURES2D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_FEATURES)) +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) + keypoint.setDetectorParameter("ORB", "nLevels", 1); +#else cv::Ptr orb_detector = keypoint.getDetector("ORB").dynamicCast(); if (orb_detector) { orb_detector->setNLevels(1); } +#endif #endif } @@ -379,10 +391,9 @@ int main(int argc, char **argv) while (!quit) { double t_begin = vpTime::measureTimeMs(); -#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ - defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif @@ -538,15 +549,20 @@ int main(int argc, char **argv) catch (const vpException &e) { std::cout << "Catch a ViSP exception: " << e << std::endl; } -#elif defined(VISP_HAVE_OPENCV) - (void)argc; - (void)argv; +} + +#else + +int main() +{ +#if defined(VISP_HAVE_OPENCV) std::cout << "Install a 3rd party dedicated to frame grabbing (dc1394, cmu1394, v4l2, OpenCV, FlyCapture, " - "Realsense2), configure and build ViSP again to use this example" + << "Realsense2), configure and build ViSP again to use this tutorial." << std::endl; #else - (void)argc; - (void)argv; - std::cout << "Install OpenCV 3rd party, configure and build ViSP again to use this example" << std::endl; + std::cout << "Install OpenCV 3rd party, configure and build ViSP again to use this tutorial." << std::endl; #endif + return EXIT_SUCCESS; } + +#endif diff --git a/tutorial/tracking/moving-edges/tutorial-me-ellipse-tracker.cpp b/tutorial/tracking/moving-edges/tutorial-me-ellipse-tracker.cpp index cbfb2291bb..553520fe05 100644 --- a/tutorial/tracking/moving-edges/tutorial-me-ellipse-tracker.cpp +++ b/tutorial/tracking/moving-edges/tutorial-me-ellipse-tracker.cpp @@ -1,46 +1,103 @@ //! \example tutorial-me-ellipse-tracker.cpp +#include + #include +//! [Undef grabber] +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ + defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) + #ifdef VISP_HAVE_MODULE_SENSOR #include #include +#include +#include #include #endif + #include #include #include #include -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif int main() { -#if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif try { vpImage I; + int opt_device = 0; // For OpenCV and V4l2 grabber to set the camera device -#if defined(VISP_HAVE_DC1394) - vp1394TwoGrabber g(false); + //! [Grabber] +#if defined(VISP_HAVE_V4L2) + vpV4l2Grabber g; + std::ostringstream device; + device << "/dev/video" << opt_device; + std::cout << "Use Video 4 Linux grabber on device " << device.str() << std::endl; + g.setDevice(device.str()); + g.setScale(1); + g.open(I); +#elif defined(VISP_HAVE_DC1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use DC1394 grabber" << std::endl; + vp1394TwoGrabber g; + g.open(I); #elif defined(VISP_HAVE_CMU1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use CMU1394 grabber" << std::endl; vp1394CMUGrabber g; -#elif defined(VISP_HAVE_V4L2) - vpV4l2Grabber g; -#elif defined(HAVE_OPENCV_VIDEOIO) - cv::VideoCapture g(0); // open the default camera - if (!g.isOpened()) { // check if we succeeded + g.open(I); +#elif defined(VISP_HAVE_FLYCAPTURE) + (void)opt_device; // To avoid non used warning + std::cout << "Use FlyCapture grabber" << std::endl; + vpFlyCaptureGrabber g; + g.open(I); +#elif defined(VISP_HAVE_REALSENSE2) + (void)opt_device; // To avoid non used warning + std::cout << "Use Realsense 2 grabber" << std::endl; + vpRealSense2 g; + rs2::config config; + config.disable_stream(RS2_STREAM_DEPTH); + config.disable_stream(RS2_STREAM_INFRARED); + config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); + g.open(config); + g.acquire(I); + + std::cout << "Read camera parameters from Realsense device" << std::endl; + cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; + cv::VideoCapture g(opt_device); // Open the default camera + if (!g.isOpened()) { // Check if we succeeded std::cout << "Failed to open the camera" << std::endl; return EXIT_FAILURE; } cv::Mat frame; + g >> frame; // get a new frame from camera + vpImageConvert::convert(frame, I); #endif + //! [Grabber] -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #endif @@ -71,21 +128,40 @@ int main() ellipse.initTracking(I); //! [me ellipse container] - while (1) { -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) + bool quit = false; + while (! quit) { +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif vpDisplay::display(I); + vpDisplay::displayText(I, 20, 20, "Click to quit", vpColor::red); ellipse.track(I); ellipse.display(I, vpColor::red); + if (vpDisplay::getClick(I, false)) { + quit = true; + } vpDisplay::flush(I); } } catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } +} + +#else + +int main() +{ +#if defined(VISP_HAVE_OPENCV) + std::cout << "Install a 3rd party dedicated to frame grabbing (dc1394, cmu1394, v4l2, OpenCV, FlyCapture, " + << "Realsense2), configure and build ViSP again to use this tutorial." + << std::endl; +#else + std::cout << "Install OpenCV 3rd party, configure and build ViSP again to use this tutorial." << std::endl; #endif + return EXIT_SUCCESS; } +#endif diff --git a/tutorial/tracking/moving-edges/tutorial-me-line-tracker.cpp b/tutorial/tracking/moving-edges/tutorial-me-line-tracker.cpp index 56807bdd5f..a00a7dd8a7 100644 --- a/tutorial/tracking/moving-edges/tutorial-me-line-tracker.cpp +++ b/tutorial/tracking/moving-edges/tutorial-me-line-tracker.cpp @@ -1,9 +1,31 @@ //! \example tutorial-me-line-tracker.cpp +#include + #include + +//! [Undef grabber] +// #undef VISP_HAVE_V4L2 +// #undef VISP_HAVE_DC1394 +// #undef VISP_HAVE_CMU1394 +// #undef VISP_HAVE_FLYCAPTURE +// #undef VISP_HAVE_REALSENSE2 +// #undef HAVE_OPENCV_HIGHGUI +// #undef HAVE_OPENCV_VIDEOIO +//! [Undef grabber] + +#if (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \ + defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) || \ + ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))) && \ + ((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_FEATURES2D)) || \ + ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D) && defined(HAVE_OPENCV_FEATURES)) + #ifdef VISP_HAVE_MODULE_SENSOR //! [camera headers] #include #include +#include +#include #include //! [camera headers] #endif @@ -16,13 +38,14 @@ #include //! [me line headers] -#if defined(HAVE_OPENCV_VIDEOIO) -#include +#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) +#include // for cv::VideoCapture +#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO) +#include // for cv::VideoCapture #endif int main() { -#if (defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -32,25 +55,59 @@ int main() //! [image container] //! [grabber container] -#if defined(VISP_HAVE_DC1394) - vp1394TwoGrabber g(false); + int opt_device = 0; // For OpenCV and V4l2 grabber to set the camera device +#if defined(VISP_HAVE_V4L2) + vpV4l2Grabber g; + std::ostringstream device; + device << "/dev/video" << opt_device; + std::cout << "Use Video 4 Linux grabber on device " << device.str() << std::endl; + g.setDevice(device.str()); + g.setScale(1); + g.open(I); +#elif defined(VISP_HAVE_DC1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use DC1394 grabber" << std::endl; + vp1394TwoGrabber g; + g.open(I); #elif defined(VISP_HAVE_CMU1394) + (void)opt_device; // To avoid non used warning + std::cout << "Use CMU1394 grabber" << std::endl; vp1394CMUGrabber g; -#elif defined(VISP_HAVE_V4L2) - vpV4l2Grabber g; -#elif defined(HAVE_OPENCV_VIDEOIO) - cv::VideoCapture g(0); // open the default camera - if (!g.isOpened()) { // check if we succeeded + g.open(I); +#elif defined(VISP_HAVE_FLYCAPTURE) + (void)opt_device; // To avoid non used warning + std::cout << "Use FlyCapture grabber" << std::endl; + vpFlyCaptureGrabber g; + g.open(I); +#elif defined(VISP_HAVE_REALSENSE2) + (void)opt_device; // To avoid non used warning + std::cout << "Use Realsense 2 grabber" << std::endl; + vpRealSense2 g; + rs2::config config; + config.disable_stream(RS2_STREAM_DEPTH); + config.disable_stream(RS2_STREAM_INFRARED); + config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30); + g.open(config); + g.acquire(I); + + std::cout << "Read camera parameters from Realsense device" << std::endl; + cam = g.getCameraParameters(RS2_STREAM_COLOR, vpCameraParameters::perspectiveProjWithoutDistortion); +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) + std::cout << "Use OpenCV grabber on device " << opt_device << std::endl; + cv::VideoCapture g(opt_device); // Open the default camera + if (!g.isOpened()) { // Check if we succeeded std::cout << "Failed to open the camera" << std::endl; return EXIT_FAILURE; } cv::Mat frame; + g >> frame; // get a new frame from camera + vpImageConvert::convert(frame, I); #endif //! [grabber container] //! [first image acquisition] -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; // get a new frame from camera vpImageConvert::convert(frame, I); #endif @@ -88,16 +145,21 @@ int main() //! [me line container] //! [loop] - while (1) { -#if defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_CMU1394) + bool quit = false; + while (! quit) { +#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2) g.acquire(I); -#elif defined(HAVE_OPENCV_VIDEOIO) +#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)) g >> frame; vpImageConvert::convert(frame, I); #endif vpDisplay::display(I); + vpDisplay::displayText(I, 20, 20, "Click to quit", vpColor::red); line.track(I); line.display(I, vpColor::red); + if (vpDisplay::getClick(I, false)) { + quit = true; + } vpDisplay::flush(I); } //! [loop] @@ -105,5 +167,19 @@ int main() catch (const vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } +} + +#else + +int main() +{ +#if defined(VISP_HAVE_OPENCV) + std::cout << "Install a 3rd party dedicated to frame grabbing (dc1394, cmu1394, v4l2, OpenCV, FlyCapture, " + << "Realsense2), configure and build ViSP again to use this tutorial." + << std::endl; +#else + std::cout << "Install OpenCV 3rd party, configure and build ViSP again to use this tutorial." << std::endl; #endif + return EXIT_SUCCESS; } +#endif