ViSP  2.10.0
vpDetectorDataMatrixCode Class Reference

#include <vpDetectorDataMatrixCode.h>

+ Inheritance diagram for vpDetectorDataMatrixCode:

Public Member Functions

 vpDetectorDataMatrixCode ()
 
virtual ~vpDetectorDataMatrixCode ()
 
bool detect (const vpImage< unsigned char > &I)
 
std::vector< std::vector< vpImagePoint > > & getPolygon ()
 
std::vector< vpImagePoint > & getPolygon (size_t i)
 
std::string & getMessage (size_t i)
 
std::vector< std::string > & getMessage ()
 
size_t getNbObjects () const
 
vpImagePoint getCog (size_t i) const
 
vpRect getBBox (size_t i) const
 

Protected Attributes

std::vector< std::vector< vpImagePoint > > m_polygon
 
std::vector< std::string > m_message
 
size_t m_nb_objects
 

Detailed Description

Base class for bar code detector. This class is a wrapper over libdmtx available from http://www.libdmtx.org/

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 <visp/vpDetectorDataMatrixCode.h>
#include <visp/vpImageIo.h>
int main()
{
#ifdef VISP_HAVE_DMTX
vpImageIo::read(I, "bar-code.pgm");
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
}

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"

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

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

Definition at line 113 of file vpDetectorDataMatrixCode.h.

Constructor & Destructor Documentation

vpDetectorDataMatrixCode::vpDetectorDataMatrixCode ( )

Default constructor that does nothing.

Definition at line 54 of file vpDetectorDataMatrixCode.cpp.

virtual vpDetectorDataMatrixCode::~vpDetectorDataMatrixCode ( )
inlinevirtual

Definition at line 117 of file vpDetectorDataMatrixCode.h.

Member Function Documentation

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

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

Parameters
I: Input image.

Implements vpDetectorBase.

Definition at line 63 of file vpDetectorDataMatrixCode.cpp.

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

vpRect vpDetectorBase::getBBox ( size_t  i) const
inlineinherited

Return the bounding box of the ith object.

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

Definition at line 141 of file vpDetectorBase.h.

vpImagePoint vpDetectorBase::getCog ( size_t  i) const
inlineinherited

Return the center of gravity location of the ith object.

Definition at line 129 of file vpDetectorBase.h.

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

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

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

Definition at line 108 of file vpDetectorBase.h.

References vpException::badValue.

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

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

Definition at line 118 of file vpDetectorBase.h.

size_t vpDetectorBase::getNbObjects ( ) const
inlineinherited

Return the number of objects that are detected.

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

Definition at line 125 of file vpDetectorBase.h.

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

Returns object container box as a vector of points.

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

Definition at line 90 of file vpDetectorBase.h.

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

Returns ith object container box as a vector of points.

Definition at line 98 of file vpDetectorBase.h.

References vpException::badValue.

Member Data Documentation

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

Message attached to each object.

Definition at line 68 of file vpDetectorBase.h.

Referenced by vpDetectorFace::detect(), detect(), and vpDetectorQRCode::detect().

size_t vpDetectorBase::m_nb_objects
protectedinherited

Number of detected objects.

Definition at line 69 of file vpDetectorBase.h.

Referenced by vpDetectorFace::detect(), detect(), and vpDetectorQRCode::detect().

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

For each object, defines the polygon that contains the object.

Definition at line 67 of file vpDetectorBase.h.

Referenced by vpDetectorFace::detect(), detect(), and vpDetectorQRCode::detect().