Visual Servoing Platform  version 3.6.0 under development (2023-09-29)
vpDetectorQRCode Class Reference

#include <visp3/detection/vpDetectorQRCode.h>

+ Inheritance diagram for vpDetectorQRCode:

Public Member Functions

 vpDetectorQRCode ()
virtual ~vpDetectorQRCode ()
bool detect (const vpImage< unsigned char > &I)
Inherited functionalities from vpDetectorBase
vpRect getBBox (size_t i) const
vpImagePoint getCog (size_t i) const
std::vector< std::string > & getMessage ()
std::string & getMessage (size_t i)
size_t getNbObjects () const
std::vector< std::vector< vpImagePoint > > & getPolygon ()
std::vector< vpImagePoint > & getPolygon (size_t i)
void setTimeout (unsigned long timeout_ms)

Protected Attributes

zbar::ImageScanner m_scanner
std::vector< std::vector< vpImagePoint > > m_polygon
std::vector< std::string > m_message
size_t m_nb_objects
unsigned long m_timeout_ms

Detailed Description

Base class for bar code detector. This class is a wrapper over libzbar available from Installation instructions are provided here

The detect() function allows to detect multiple QR codes in an image. Once detected, for each QR code it is possible to retrieve the location of the corners using getPolygon(), the encoded message using getMessage(), the bounding box using getBBox() and the center of gravity using getCog().

The following sample code shows how to use this class to detect QR codes in an image.

#include <visp3/detection/vpDetectorQRCode.h>
#include <visp3/io/vpImageIo.h>
int main()
vpImageIo::read(I, "bar-code.pgm");
vpDetectorQRCode detector;
bool status = detector.detect(I);
if (status) {
for(size_t i=0; i < detector.getNbObjects(); i++) {
std::cout << "Bar code " << i << ":" << std::endl;
std::vector<vpImagePoint> p = detector.getPolygon(i);
for(size_t j=0; j < p.size(); j++)
std::cout << " Point " << j << ": " << p[j] << std::endl;
std::cout << " Message: \"" << detector.getMessage(i) << "\"" << std::endl;
std::vector< std::vector< vpImagePoint > > & getPolygon()
size_t getNbObjects() const
std::vector< std::string > & getMessage()
bool detect(const vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:143

The previous example may produce results like:

Bar code 0:
Point 0: 48, 212
Point 1: 57, 84
Point 2: 188, 92
Point 3: 183, 220
Message: "qrcode 2"
Bar code 1:
Point 0: 26, 550
Point 1: 35, 409
Point 2: 174, 414
Point 3: 167, 555
Message: "qrcode 1"

Other examples are also provided in tutorial-barcode-detector.cpp and tutorial-barcode-detector-live.cpp

tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, and tutorial-pose-from-qrcode-image.cpp.

Definition at line 111 of file vpDetectorQRCode.h.

Constructor & Destructor Documentation

◆ vpDetectorQRCode()

vpDetectorQRCode::vpDetectorQRCode ( )

Default constructor.

Definition at line 45 of file vpDetectorQRCode.cpp.

References m_scanner.

◆ ~vpDetectorQRCode()

virtual vpDetectorQRCode::~vpDetectorQRCode ( )

Definition at line 118 of file vpDetectorQRCode.h.

Member Function Documentation

◆ detect()

bool vpDetectorQRCode::detect ( const vpImage< unsigned char > &  I)

Detect QR codes in the image. Return true if a code is detected, false otherwise.

I: Input image.

Implements vpDetectorBase.


Definition at line 57 of file vpDetectorQRCode.cpp.

References vpImage< Type >::bitmap, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpDetectorBase::m_message, vpDetectorBase::m_nb_objects, vpDetectorBase::m_polygon, and m_scanner.

◆ getBBox()

◆ getCog()

vpImagePoint vpDetectorBase::getCog ( size_t  i) const

Return the center of gravity location of the ith object.

mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, and tutorial-flir-ptu-ibvs.cpp.

Definition at line 76 of file vpDetectorBase.cpp.

References vpDetectorBase::m_polygon.

◆ getMessage() [1/2]

std::vector<std::string>& vpDetectorBase::getMessage ( )

◆ getMessage() [2/2]

std::string & vpDetectorBase::getMessage ( size_t  i)

Returns the contained message of the ith object if there is one.

Definition at line 64 of file vpDetectorBase.cpp.

References vpException::badValue, vpDetectorBase::m_message, and vpDetectorBase::m_polygon.

◆ getNbObjects()

◆ getPolygon() [1/2]

◆ getPolygon() [2/2]

std::vector< vpImagePoint > & vpDetectorBase::getPolygon ( size_t  i)

Returns ith object container box as a vector of points.

Definition at line 52 of file vpDetectorBase.cpp.

References vpException::badValue, and vpDetectorBase::m_polygon.

◆ setTimeout()

void vpDetectorBase::setTimeout ( unsigned long  timeout_ms)

Set detector timeout in milli-seconds. When set to 0, there is no timeout.

Definition at line 126 of file vpDetectorBase.h.

Referenced by vpDetectorDataMatrixCode::vpDetectorDataMatrixCode().

Member Data Documentation

◆ m_message

std::vector<std::string> vpDetectorBase::m_message

◆ m_nb_objects

size_t vpDetectorBase::m_nb_objects

Number of detected objects.

Definition at line 66 of file vpDetectorBase.h.

Referenced by vpDetectorFace::detect(), vpDetectorAprilTag::detect(), vpDetectorDataMatrixCode::detect(), and detect().

◆ m_polygon

std::vector<std::vector<vpImagePoint> > vpDetectorBase::m_polygon

◆ m_scanner

zbar::ImageScanner vpDetectorQRCode::m_scanner

QR code detector.

Definition at line 114 of file vpDetectorQRCode.h.

Referenced by detect(), and vpDetectorQRCode().

◆ m_timeout_ms

unsigned long vpDetectorBase::m_timeout_ms

Detection timeout.

Definition at line 67 of file vpDetectorBase.h.

Referenced by vpDetectorDataMatrixCode::detect().