Common Vision Blox 15.0
Loading...
Searching...
No Matches
cvb_codereader/Cvb++/CppCodeReading

This example program is located in your CVB installation under %CVB%Tutorial/cvb_codereader/Cvb++/CppCodeReading.

main.cpp:

// Example for **reading codes**: This example demonstrates how to decode Data Matrix codes in a image.
#include <iostream>
#include <cvb/code_reader/code_reader.hpp>
#include <cvb/image.hpp>
using namespace Cvb::CodeReader;
void PrintResults(const std::vector<Result> &results);
int main() {
try {
// Create a decoder.
auto decoder = Decoder::Create();
// Configure decoding.
// Retrieve the configuration object for a specific symbology.
auto &config = decoder->Config<Symbology::DataMatrix>();
// Enable decoding for the selected symbology.
config.Enable();
// Optionally, configure additional parameters.
config.SetPolarity(Config::Polarity::DarkOnLight);
// Alternatively, the configuration can be performed in a more concise
// manner:
// decoder->Config<Symbology::DataMatrix>().Enable().SetPolarity(Config::Polarity::DarkOnLight);
// Load the image and decode.
const auto imageFile =
CVB_LIT("tutorial/CodeReader/Images/DataMat/Surrounded.bmp");
const auto image = Cvb::Image::Load(imageFile);
const auto results = decoder->Execute(image->Plane(0));
// Display results.
PrintResults(results);
} catch (const std::exception &error) {
std::cout << error.what() << std::endl;
}
return 0;
}
void PrintResults(const std::vector<Result> &results) {
std::cout << results.size() << " code(s) found.\n";
for (const auto result : results) {
if (result.DecodeStatus() == DecodeStatus::Success) {
std::cout
<< " ------------------------------------------------------------\n";
std::cout << " code with content:\n";
std::cout << result.Data() << "\n";
std::cout << " found at center: (" << result.Center().X() << "/"
<< result.Center().Y() << ")\n";
std::cout << " with corners at: ";
for (int k = 0; k < 4; k++)
std::cout << "(" << result.Corners()[k].X() << "/"
<< result.Corners()[k].Y() << ") ";
std::cout << "\n";
// optional 2D results
if (result.Result2D()) {
const auto result2D = result.Result2D();
std::cout << " size (width x height): " << result2D->Size().Width()
<< " x " << result2D->Size().Height() << "\n";
std::cout << " rows x columns: " << result2D->Rows() << " x "
<< result2D->Columns() << "\n";
std::cout << " Quality: " << result2D->Quality() << "\n";
}
std::cout
<< " "
"------------------------------------------------------------\n\n";
} else {
std::cout << " Decoding failed.\n";
}
}
}
static std::unique_ptr< Decoder > Create()
static std::unique_ptr< Image > Load(const String &fileName)
String InstallPath()