4 #include <visp3/core/vpConfig.h>
17 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && defined(VISP_HAVE_PUGIXML) && \
18 (defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \
19 defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2)) || \
20 ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
22 #ifdef VISP_HAVE_MODULE_SENSOR
23 #include <visp3/sensor/vp1394CMUGrabber.h>
24 #include <visp3/sensor/vp1394TwoGrabber.h>
25 #include <visp3/sensor/vpFlyCaptureGrabber.h>
26 #include <visp3/sensor/vpRealSense2.h>
27 #include <visp3/sensor/vpV4l2Grabber.h>
29 #include <visp3/core/vpXmlParserCamera.h>
30 #include <visp3/gui/vpDisplayGDI.h>
31 #include <visp3/gui/vpDisplayOpenCV.h>
32 #include <visp3/gui/vpDisplayX.h>
34 #if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
35 #include <opencv2/highgui/highgui.hpp>
36 #elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
37 #include <opencv2/videoio/videoio.hpp>
40 #include "pose_helper.h"
42 int main(
int argc,
char **argv)
44 #ifdef ENABLE_VISP_NAMESPACE
48 std::string opt_intrinsic_file;
49 std::string opt_camera_name;
50 double opt_square_width = 0.12;
53 for (
int i = 1; i < argc; i++) {
54 if (std::string(argv[i]) ==
"--intrinsic" && i + 1 < argc) {
55 opt_intrinsic_file = std::string(argv[++i]);
57 else if (std::string(argv[i]) ==
"--camera-name" && i + 1 < argc) {
58 opt_camera_name = std::string(argv[++i]);
60 else if (std::string(argv[i]) ==
"--camera-device" && i + 1 < argc) {
61 opt_device = atoi(argv[++i]);
63 else if (std::string(argv[i]) ==
"--square-width" && i + 1 < argc) {
64 opt_device = atoi(argv[++i]);
66 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
67 std::cout <<
"\nUsage: " << argv[0]
68 <<
" [--camera-device <camera device> (default: 0)]"
69 <<
" [--intrinsic <xml calibration file> (default: empty)]"
70 <<
" [--camera-name <camera name in xml calibration file> (default: empty)]"
71 <<
" [--square-width <square width in meter (default: 0.12)]"
74 <<
"Example using default camera parameters and square size:\n"
75 <<
" " << argv[0] <<
"\n"
77 <<
"Example fully tuned for a 0.1m x 0.1m square:\n"
78 <<
" " << argv[0] <<
" --intrinsic camera.xml --camera-name Camera --square-width 0.1\n"
88 #if defined(VISP_HAVE_V4L2)
90 std::ostringstream device;
91 device <<
"/dev/video" << opt_device;
92 std::cout <<
"Use Video 4 Linux grabber on device " << device.str() << std::endl;
97 #elif defined(VISP_HAVE_DC1394)
99 std::cout <<
"Use DC1394 grabber" << std::endl;
103 #elif defined(VISP_HAVE_CMU1394)
105 std::cout <<
"Use CMU1394 grabber" << std::endl;
109 #elif defined(VISP_HAVE_FLYCAPTURE)
111 std::cout <<
"Use FlyCapture grabber" << std::endl;
115 #elif defined(VISP_HAVE_REALSENSE2)
117 std::cout <<
"Use Realsense 2 grabber" << std::endl;
120 config.disable_stream(RS2_STREAM_DEPTH);
121 config.disable_stream(RS2_STREAM_INFRARED);
122 config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30);
126 std::cout <<
"Read camera parameters from Realsense device" << std::endl;
128 #elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
129 std::cout <<
"Use OpenCV grabber on device " << opt_device << std::endl;
130 cv::VideoCapture g(opt_device);
132 std::cout <<
"Failed to open the camera" << std::endl;
144 if (!opt_intrinsic_file.empty() && !opt_camera_name.empty()) {
145 std::cout <<
"Intrinsic file: " << opt_intrinsic_file << std::endl;
146 std::cout <<
"Camera name : " << opt_camera_name << std::endl;
149 std::cout <<
"Succeed to read camera parameters from xml file" << std::endl;
152 std::cout <<
"Unable to read camera parameters from xml file" << std::endl;
156 std::cout <<
"Square width : " << opt_square_width << std::endl;
157 std::cout << cam << std::endl;
162 std::vector<vpDot2> dot(4);
163 std::vector<vpPoint> point;
164 std::vector<vpImagePoint> ip;
165 double L = opt_square_width / 2.;
166 point.push_back(
vpPoint(-L, -L, 0));
167 point.push_back(
vpPoint(L, -L, 0));
168 point.push_back(
vpPoint(L, L, 0));
169 point.push_back(
vpPoint(-L, L, 0));
171 #if defined(VISP_HAVE_X11)
173 #elif defined(VISP_HAVE_GDI)
175 #elif defined(HAVE_OPENCV_HIGHGUI)
180 bool apply_cv =
false;
186 #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_CMU1394) || \
187 defined(VISP_HAVE_FLYCAPTURE) || defined(VISP_HAVE_REALSENSE2)
189 #elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
196 ip = track(I, dot, init_cv);
197 computePose(point, ip, cam, init_cv, cMo);
204 std::stringstream ss;
205 ss <<
"Translation: " << std::setprecision(5) << pose[0] <<
" " << pose[1] <<
" " << pose[2] <<
" [m]";
208 ss <<
"Rotation tu: " << std::setprecision(4) <<
vpMath::deg(pose[3]) <<
" " <<
vpMath::deg(pose[4]) <<
" "
214 std::cout <<
"Computer vision failure." << std::endl;
236 std::stringstream ss;
244 std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;
252 std::cout <<
"There are missing 3rd parties to run this tutorial" << std::endl;
Firewire cameras video capture based on CMU 1394 Digital Camera SDK.
void open(vpImage< unsigned char > &I)
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void open(vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
@ perspectiveProjWithoutDistortion
Perspective projection without distortion model.
static const vpColor none
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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.
const char * getMessage() const
void open(vpImage< unsigned char > &I)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int getWidth() const
unsigned int getHeight() const
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())
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void open(vpImage< unsigned char > &I)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setDevice(const std::string &devname)
XML parser to load and save intrinsic camera parameters.
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, unsigned int image_width=0, unsigned int image_height=0, bool verbose=true)
VISP_EXPORT double measureTimeMs()