2#include <visp3/core/vpConfig.h>
3#ifdef VISP_HAVE_MODULE_SENSOR
4#include <visp3/sensor/vpRealSense2.h>
6#include <visp3/gui/vpDisplayFactory.h>
8#include "pose_helper.h"
10int main(
int argc,
char **argv)
12#if defined(VISP_HAVE_DISPLAY) && \
13 defined(VISP_HAVE_REALSENSE2) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
14#ifdef ENABLE_VISP_NAMESPACE
17#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
18 std::shared_ptr<vpDisplay> display;
24 double opt_square_width = 0.12;
25 int opt_camera_index = 1;
27 for (
int i = 1;
i < argc;
i++) {
28 if (std::string(argv[i]) ==
"--camera-index" && i + 1 < argc) {
29 opt_camera_index = atoi(argv[++i]);
31 else if (std::string(argv[i]) ==
"--square-width" && i + 1 < argc) {
32 opt_square_width = atoi(argv[++i]);
34 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
35 std::cout <<
"\nUsage: " << argv[0]
36 <<
" [--camera-index <1.Left | 2.Right> (default: 1)]"
37 <<
" [--square-width <square width in meter (default: 0.12)]"
40 <<
"\nExample using right camera and square size 0.1:\n"
41 <<
" " << argv[0] <<
"--camera-index 2 --square-width 0.1\n"
50 std::cout <<
"Use Realsense 2 grabber" << std::endl;
53 config.enable_stream(RS2_STREAM_FISHEYE, 1);
54 config.enable_stream(RS2_STREAM_FISHEYE, 2);
57 if (opt_camera_index == 1)
58 g.
acquire(&I,
nullptr,
nullptr);
60 g.
acquire(
nullptr, &I,
nullptr);
62 std::cout <<
"Read camera parameters from Realsense device" << std::endl;
68 std::cout <<
"Square width : " << opt_square_width << std::endl;
69 std::cout <<
cam << std::endl;
74 std::vector<vpDot2> dot(4);
75 std::vector<vpPoint> point;
76 std::vector<vpImagePoint> ip;
77 double L = opt_square_width / 2.;
78 point.push_back(
vpPoint(-L, -L, 0));
79 point.push_back(
vpPoint(L, -L, 0));
80 point.push_back(
vpPoint(L, L, 0));
81 point.push_back(
vpPoint(-L, L, 0));
83#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
90 bool apply_cv =
false;
96 if (opt_camera_index == 1)
97 g.
acquire(&I,
nullptr,
nullptr);
99 g.
acquire(
nullptr, &I,
nullptr);
104 ip = track(I, dot, init_cv);
105 computePose(point, ip, cam, init_cv, cMo);
112 std::stringstream ss;
113 ss <<
"Translation: " << std::setprecision(5) << pose[0] <<
" " << pose[1] <<
" " << pose[2] <<
" [m]";
116 ss <<
"Rotation tu: " << std::setprecision(4) <<
vpMath::deg(pose[3]) <<
" " <<
vpMath::deg(pose[4]) <<
" "
122 std::cout <<
"Computer vision failure." << std::endl;
144 std::stringstream ss;
152 std::cout <<
"Catch an exception: " <<
e.getMessage() << std::endl;
155#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
156 if (display !=
nullptr) {
160#elif !defined(VISP_HAVE_REALSENSE2)
163 std::cout <<
"You do not realsense2 SDK functionality enabled..." << std::endl;
164 std::cout <<
"Tip:" << std::endl;
165 std::cout <<
"- Install librealsense2, configure again ViSP using cmake and build again this example" << std::endl;
167#elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
170 std::cout <<
"Install a 3rd party dedicated to image display (X11, GDI, OpenCV), configure and build ViSP again to "
173#elif !(RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
176 std::cout <<
"Install librealsense version > 2.31.0" << std::endl;
Generic class defining intrinsic camera parameters.
@ ProjWithKannalaBrandtDistortion
Projection with Kannala-Brandt distortion model.
static const vpColor none
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
static double deg(double rad)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Implementation of a pose vector and operations on poses.
vpCameraParameters getCameraParameters(const rs2_stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion, int index=-1) const
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()