4#include <visp3/core/vpConfig.h>
13#if (defined(VISP_HAVE_ZBAR) || defined(VISP_HAVE_DMTX)) && (defined(VISP_HAVE_V4L2) || \
14 ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
16#include <visp3/core/vpImageConvert.h>
17#include <visp3/detection/vpDetectorDataMatrixCode.h>
18#include <visp3/detection/vpDetectorQRCode.h>
19#include <visp3/gui/vpDisplayFactory.h>
20#ifdef VISP_HAVE_MODULE_SENSOR
21#include <visp3/sensor/vpV4l2Grabber.h>
24#if (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
25#include <opencv2/highgui/highgui.hpp>
26#elif (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
27#include <opencv2/videoio/videoio.hpp>
30int main(
int argc,
const char **argv)
32#ifdef ENABLE_VISP_NAMESPACE
38 for (
int i = 1;
i < argc;
i++) {
39 if (std::string(argv[i]) ==
"--device" && i + 1 < argc) {
40 opt_device = atoi(argv[++i]);
42 else if (std::string(argv[i]) ==
"--code-type" && i + 1 < argc) {
43 opt_barcode = atoi(argv[++i]);
45 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
46 std::cout <<
"Usage: " << argv[0]
47 <<
" [--device <camera number>]"
48 <<
" [--code-type <0 for QR code | 1 for DataMatrix code>]"
54 std::cout <<
"Use device: " << opt_device << std::endl;
56#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
57 std::shared_ptr<vpDisplay> display;
65#if defined(VISP_HAVE_V4L2)
67 std::ostringstream device;
68 device <<
"/dev/video" << opt_device;
72#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
73 cv::VideoCapture cap(opt_device);
74 if (!cap.isOpened()) {
75 std::cout <<
"Failed to open the camera" << std::endl;
84#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
92#if (defined(VISP_HAVE_ZBAR) && defined(VISP_HAVE_DMTX))
97#elif defined(VISP_HAVE_ZBAR)
100#elif defined(VISP_HAVE_DMTX)
107#if defined(VISP_HAVE_V4L2)
109#elif ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI))|| ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO))
116 bool status = detector->
detect(I);
117 std::ostringstream legend;
118 legend << detector->
getNbObjects() <<
" bar code detected";
123 std::vector<vpImagePoint>
p = detector->
getPolygon(i);
128 for (
size_t j = 0;
j <
p.size();
j++) {
130 std::ostringstream number;
145 std::cout <<
"Catch an exception: " <<
e << std::endl;
147#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
148 if (display !=
nullptr) {
158 std::cout <<
"There are missing 3rd parties to run this tutorial" << std::endl;
static const vpColor blue
static const vpColor green
std::vector< std::vector< vpImagePoint > > & getPolygon()
vpRect getBBox(size_t i) const
std::vector< std::string > & getMessage()
size_t getNbObjects() const
virtual bool detect(const vpImage< unsigned char > &I)=0
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 displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
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.
Defines a rectangle in the plane.
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setDevice(const std::string &devname)
void acquire(vpImage< unsigned char > &I)
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.