CVB++ 15.0
Loading...
Searching...
No Matches

Class for decoding. More...

#include <decl_decoder.hpp>

Public Member Functions

std::vector< ResultExecute (const ImagePlane &plane, const Rect< int > &aoi)
 Performs the decoding.
 
std::vector< ResultExecute (const ImagePlane &plane)
 Performs the decoding.
 
template<class Rep, class Period>
TimeLimitedDecoderResult ExecuteFor (const ImagePlane &plane, const Rect< int > &aoi, const std::chrono::duration< Rep, Period > &timeSpan)
 Performs the decoding within a specified time limit.
 
template<class Rep, class Period>
TimeLimitedDecoderResult ExecuteFor (const ImagePlane &plane, const std::chrono::duration< Rep, Period > &timeSpan)
 Performs the decoding within a specified time limit.
 
template<Symbology SYM>
Config::Mapper< SYM >::Type & Config ()
 Retrieves the configuration object for a specific symbology.
 
void SetBasicInkjetDPMEnabled (bool value)
 Enables or disables the reading of Basic Inkjet DPM (Direct Part Marking) codes.
 
bool IsBasicInkjetDPMEnabled () const
 Checks whether the Basic Inkjet DPM mode is enabled.
 
void SetCustomPerformance (CustomPerformance value)
 Sets the custom image processing method used to optimize decoding robustness and performance.
 
CodeReader::CustomPerformance CustomPerformance () const
 Retrieves the custom image processing method used to optimize decoding robustness and performance.
 
void SetDetectorDensity (int value)
 Sets the detector density to control the search aggressiveness for small codes.
 
int DetectorDensity () const
 Retrieves the detector density to control the search aggressiveness for small codes.
 
void SetCodeSearchSpeed (int value)
 Sets the code search speed.
 
int CodeSearchSpeed () const
 Retrieves the code search speed.
 

Static Public Member Functions

static std::unique_ptr< DecoderCreate ()
 Creates and returns a new Decoder instance.
 

Detailed Description

Class for decoding.

This class provides the core functionality for detecting and decoding codes in images. Each codes type can be configured using its corresponding configuration class.

To decode an image containing a supported codes, start by creating a decoder. You can configure your decoder using the member function Decoder::Config(), which returns a reference to the desired configuration class. The configuration class is specified by the CodeReader::Symbology template. All supported codes types are enumerated in the enum class CodeReader::Symbology.

After configuring the decoder, load an image containing the codes(s) and execute the decoding process. The following code snippet demonstrates how to decode an image containing Data Matrix and QR codes:

#include <iostream>
#include <cvb/image.hpp>
#include <cvb/code_reader/code_reader.hpp>
using namespace Cvb::CodeReader;
// Create a decoder.
auto decoder = Decoder::Create();
// Retrieve the configuration object for a specific symbology.
auto& config = decoder->Config<Symbology::DataMatrix>();
// Enable decoding for the selected symbology and configure additional (optional) parameters.
config.Enable().SetPolarity(Config::Polarity::DarkOnLight);
// Alternatively, the configuration can be performed in a more concise manner:
decoder->Config<Symbology::QR>().Enable().SetPolarity(Config::Polarity::DarkOnLight);
// Load the image and decode.
auto image = Cvb::Image::Load(CVB_LIT("your_image_with_codes.bmp"));
auto results = decoder->Execute(image->Plane(0));
// Display results.
std::cout << results.size() << " codes(s) found.\n";
for (int i = 0; i < results.size(); i++)
{
std::cout << results[i].Data().c_str() << "\n";
}
static std::unique_ptr< Decoder > Create()
Creates and returns a new Decoder instance.
Definition detail_decoder.hpp:21
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition detail_image.hpp:25
@ DarkOnLight
Definition decl_config_base.hpp:186
Namespace for all decoding functionalities.
Definition decl_config_2d_codes.hpp:10
@ QR
QR code.
Definition decl_config_base.hpp:47
@ DataMatrix
Data Matrix.
Definition decl_config_base.hpp:42

Member Function Documentation

◆ CodeSearchSpeed()

int CodeSearchSpeed ( ) const
inline

Retrieves the code search speed.

For details refer to Cvb::CodeReader::Decoder::SetCodeSearchSpeed.

Returns
Value for code search speed.

◆ Config()

template<Symbology SYM>
Config::Mapper< SYM >::Type & Config ( )
inline

Retrieves the configuration object for a specific symbology.

Use this function to access the configuration settings for a particular symbology. After creating a decoder, you can obtain the desired configuration object as shown below:

auto &config = decoder->Config<Cvb::CodeReader::Symbology::DataMatrix>();
config.Enable();

Alternatively, you can utilize the fluent interface pattern for seamless configuration:

decoder->Config<Cvb::CodeReader::Symbology::DataMatrix>().Enable().SetMirroring(true);
Template Parameters
SYMThe symbology for which the configuration is retrieved.
Returns
A reference to the configuration object corresponding to the specified symbology.

◆ Create()

std::unique_ptr< Decoder > Create ( )
inlinestatic

Creates and returns a new Decoder instance.

Returns
A std::unique_ptr pointing to the newly created Decoder object.

◆ CustomPerformance()

Retrieves the custom image processing method used to optimize decoding robustness and performance.

Returns
The configured image processing method.

◆ DetectorDensity()

int DetectorDensity ( ) const
inline

Retrieves the detector density to control the search aggressiveness for small codes.

For details refer to SetDetectorDensity.

Returns
Value for detector densitiy.

◆ Execute() [1/2]

std::vector< Result > Execute ( const ImagePlane & plane)
inline

Performs the decoding.

Up to 256 codes can be detected using this function.

Parameters
planeThe image plane containing the code(s) to be decoded.
Returns
A vector of Result objects containing the decoded decoded data.

◆ Execute() [2/2]

std::vector< Result > Execute ( const ImagePlane & plane,
const Rect< int > & aoi )
inline

Performs the decoding.

For further details see function Execute(const ImagePlane &).

Parameters
planeThe image plane containing the code(s) to be decoded.
aoiThe area of interest within the image where the decoding operation will be performed.
Returns
A vector of Result objects containing the decoded decoded data.

◆ ExecuteFor() [1/2]

template<class Rep, class Period>
TimeLimitedDecoderResult ExecuteFor ( const ImagePlane & plane,
const Rect< int > & aoi,
const std::chrono::duration< Rep, Period > & timeSpan )
inline

Performs the decoding within a specified time limit.

For further details see function ExecuteFor(const ImagePlane &, const std::chrono::duration<Rep, Period> &).

Template Parameters
RepAn arithmetic type, or a class emulating an arithmetic type, representing the number of ticks.
PeriodA std::ratio representing the tick period.
Parameters
planeThe image plane containing the code(s) to be decoded.
aoiThe area of interest within the image where the decoding operation will be performed.
timeSpanThe maximum decoding time in milliseconds (0-60000).
Returns
A tuple with a vector of Result objects containing the decoded data and a flag indicating whether the time limit was reached.

◆ ExecuteFor() [2/2]

template<class Rep, class Period>
TimeLimitedDecoderResult ExecuteFor ( const ImagePlane & plane,
const std::chrono::duration< Rep, Period > & timeSpan )
inline

Performs the decoding within a specified time limit.

Starts the decoding process on the given image plane and continues until either all detectable codes have been processed or the specified time limit is reached.

The value of timeSpan must be in the range [0, 60000] milliseconds. A value of 0 disables the time limit and allows decoding to run without restriction.

Template Parameters
RepAn arithmetic type, or a class emulating an arithmetic type, representing the number of ticks.
PeriodA std::ratio representing the tick period.
Parameters
planeThe image plane containing the code(s) to be decoded.
timeSpanThe maximum decoding time in milliseconds (0-60000).
Returns
A tuple with a vector of Result objects containing the decoded data and a flag indicating whether the time limit was reached.

◆ IsBasicInkjetDPMEnabled()

bool IsBasicInkjetDPMEnabled ( ) const
inline

Checks whether the Basic Inkjet DPM mode is enabled.

Returns
true if the Basic Inkjet DPM mode is enabled, false otherwise.

◆ SetBasicInkjetDPMEnabled()

void SetBasicInkjetDPMEnabled ( bool value)
inline

Enables or disables the reading of Basic Inkjet DPM (Direct Part Marking) codes.

This setting applies exclusively to DPM codes. Enabling Basic Inkjet DPM allows for the reading of low-quality inkjet images.

Parameters
valueSet to true to enable Basic Inkjet DPM, false otherwise.

◆ SetCodeSearchSpeed()

void SetCodeSearchSpeed ( int value)
inline

Sets the code search speed.

Adjusts the trade-off between decoding speed, damage tolerance, and required code contrast. The default value (0) provides maximum damage tolerance and allows detection of low-contrast codes. Higher values increase search speed but reduce damage tolerance and require higher code contrast:

0 - Maximum damage tolerance, detects low-contrast codes (default)
1 - Faster, reduced damage tolerance, detects low-contrast codes
2 - Faster, further reduced damage tolerance, detects medium-contrast codes
3 - Fastest, same damage tolerance as level 2, detects high-contrast codes only

Parameters
valueCode search speed value between 0 and 3 (inclusive).

◆ SetCustomPerformance()

void SetCustomPerformance ( CodeReader::CustomPerformance value)
inline

Sets the custom image processing method used to optimize decoding robustness and performance.

The default setting is CustomPerformance::None.

Parameters
valueValue for image processing method.

◆ SetDetectorDensity()

void SetDetectorDensity ( int value)
inline

Sets the detector density to control the search aggressiveness for small codes.

Lower values increase the robustness when decoding small or poorly printed 2D codes, but may result in longer decoding times. Higher values reduce decoding time, but may decrease robustness for small codes. The default value is 3.

Parameters
valueDetector density value between 1 and 4 (inclusive).