4#include <visp3/core/vpConfig.h>
13#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO) && \
14 (defined(VISP_HAVE_V4L2) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
15 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
17#ifdef VISP_HAVE_MODULE_SENSOR
18#include <visp3/sensor/vpV4l2Grabber.h>
20#include <visp3/core/vpImageConvert.h>
21#include <visp3/gui/vpDisplayOpenCV.h>
22#include <visp3/io/vpVideoReader.h>
23#include <visp3/klt/vpKltOpencv.h>
25#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
26#include <opencv2/highgui/highgui.hpp>
27#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
28#include <opencv2/videoio/videoio.hpp>
31int main(
int argc,
const char *argv[])
33#ifdef ENABLE_VISP_NAMESPACE
38 bool opt_init_by_click =
false;
41 for (
int i = 1;
i < argc;
i++) {
42 if (std::string(argv[i]) ==
"--init-by-click") {
43 opt_init_by_click =
true;
45 else if (std::string(argv[i]) ==
"--device" && i + 1 < argc) {
46 opt_device = atoi(argv[++i]);
48 else if (std::string(argv[i]) ==
"--help") {
49 std::cout <<
"Usage: " << argv[0] <<
" [--init-by-click] [--device <camera device>] [--help]" << std::endl;
56#if defined(VISP_HAVE_V4L2)
57 std::cout <<
"Use v4l2 grabber..." << std::endl;
59 std::ostringstream device;
60 device <<
"/dev/video" << opt_device;
64#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
65 std::cout <<
"Use OpenCV grabber..." << std::endl;
66 cv::VideoCapture g(opt_device);
68 std::cout <<
"Failed to open the camera" << std::endl;
90 tracker.setHarrisFreeParameter(0.04);
96 if (opt_init_by_click) {
98 std::vector<cv::Point2f> guess;
104 guess.push_back(cv::Point2f(
static_cast<float>(ip.
get_u()),
static_cast<float>(ip.
get_v())));
112 tracker.initTracking(cvI, guess);
119#if defined(VISP_HAVE_V4L2)
121#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
138 std::cout <<
"Catch an exception: " <<
e << std::endl;
148#if !defined(HAVE_OPENCV_HIGHGUI)
149 std::cout <<
"This tutorial needs OpenCV highgui module that is missing." << std::endl;
151#if !defined(HAVE_OPENCV_IMGPROC)
152 std::cout <<
"This tutorial needs OpenCV imgproc module that is missing." << std::endl;
154#if !defined(HAVE_OPENCV_VIDEO)
155 std::cout <<
"This tutorial needs OpenCV video module that is missing." << std::endl;
157#if !(defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_OPENCV) && \
158 (((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
159 ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))))
160 std::cout <<
"This tutorial needs V4l2 or OpenCV grabber capabilities." << std::endl;
static const vpColor green
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 displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void open(vpImage< unsigned char > &I)
void setDevice(const std::string &devname)
void acquire(vpImage< unsigned char > &I)
VISP_EXPORT int wait(double t0, double t)