Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDetectorDataMatrixCode Class Reference

#include <vpDetectorDataMatrixCode.h>

Inheritance diagram for vpDetectorDataMatrixCode:

Public Member Functions

 vpDetectorDataMatrixCode ()
bool detect (const vpImage< unsigned char > &I) VP_OVERRIDE

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)
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 libdmtx available from http://www.libdmtx.org. Installation instructions are provided here https://visp.inria.fr/3rd_dmtx.

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/vpDetectorDataMatrixCode.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#ifdef VISP_HAVE_DMTX
vpImageIo::read(I, "bar-code.jpg");
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;
}
}
#endif
}
std::vector< std::vector< vpImagePoint > > & getPolygon()
std::vector< std::string > & getMessage()
size_t getNbObjects() const
bool detect(const vpImage< unsigned char > &I) VP_OVERRIDE
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
Definition vpImage.h:131

The previous example may produce results like:

Bar code 0:
Point 0: 273.21, 78.9799
Point 1: 390.016, 85.1014
Point 2: 388.024, 199.185
Point 3: 269.23, 192.96
Message: "datamatrix 1"
Bar code 1:
Point 0: 262.23, 396.404
Point 1: 381.041, 402.631
Point 2: 378.92, 524.188
Point 3: 257.916, 519.962
Message: "datamatrix 2"

Tutorials & Examples

Tutorials
If you are interested in multiple QR codes detection, you may have a look at:

Examples
tutorial-barcode-detector-live.cpp, and tutorial-barcode-detector.cpp.

Definition at line 116 of file vpDetectorDataMatrixCode.h.

Constructor & Destructor Documentation

◆ vpDetectorDataMatrixCode()

BEGIN_VISP_NAMESPACE vpDetectorDataMatrixCode::vpDetectorDataMatrixCode ( )

Default constructor that does nothing except setting detection timeout to 50ms. This value could be changed using setTimeout().

Definition at line 49 of file vpDetectorDataMatrixCode.cpp.

References vpDetectorBase::setTimeout().

Member Function Documentation

◆ detect()

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

Detect datamatrix codes in the image. Return true if a code is detected, false otherwise. There is the setTimeout() function that allows to tune the value of the timeout used to detect a datamatrix code. By default, there is a timeout of 50 ms set in the constructor.

Parameters
I: Input image.

Implements vpDetectorBase.

Definition at line 58 of file vpDetectorDataMatrixCode.cpp.

References vpDetectorBase::m_message, vpDetectorBase::m_nb_objects, vpDetectorBase::m_polygon, and vpDetectorBase::m_timeout_ms.

Referenced by visp.python.rbt.xfeat.XFeatTrackingBackend.XFeatTrackingBackend::process_frame().

◆ getBBox()

vpRect vpDetectorBase::getBBox ( size_t i) const
inherited

◆ getCog()

vpImagePoint vpDetectorBase::getCog ( size_t i) const
inherited

Return the center of gravity location of the ith object.

Examples
servoBiclopsPoint2DArtVelocity.cpp, servoPololuPtuPoint2DJointVelocity.cpp, and tutorial-flir-ptu-ibvs.cpp.

Definition at line 78 of file vpDetectorBase.cpp.

References m_polygon.

Referenced by detect().

◆ getMessage() [1/2]

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

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

Examples
catchAprilTag.cpp, catchArUco.cpp, tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 98 of file vpDetectorBase.h.

References m_message.

◆ getMessage() [2/2]

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

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

Definition at line 64 of file vpDetectorBase.cpp.

References vpException::badValue, m_message, and m_polygon.

◆ getNbObjects()

◆ getPolygon() [1/2]

std::vector< std::vector< vpImagePoint > > & vpDetectorBase::getPolygon ( )
inlineinherited

Returns object container box as a vector of points.

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

Definition at line 113 of file vpDetectorBase.h.

References m_polygon.

◆ getPolygon() [2/2]

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

Returns ith object container box as a vector of points.

Definition at line 50 of file vpDetectorBase.cpp.

References vpException::badValue, and m_polygon.

◆ setTimeout()

void vpDetectorBase::setTimeout ( unsigned long timeout_ms)
inlineinherited

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

Definition at line 123 of file vpDetectorBase.h.

References m_timeout_ms.

Referenced by vpDetectorDataMatrixCode::vpDetectorDataMatrixCode().

Member Data Documentation

◆ m_message

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

◆ m_nb_objects

size_t vpDetectorBase::m_nb_objects
protectedinherited

◆ m_polygon

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

◆ m_timeout_ms

unsigned long vpDetectorBase::m_timeout_ms
protectedinherited

Detection timeout.

Definition at line 131 of file vpDetectorBase.h.

Referenced by vpDetectorDataMatrixCode::detect(), setTimeout(), vpDetectorBase(), and vpDetectorBase().