Scanbot SDK
Loading...
Searching...
No Matches
ScanbotSDK.hpp
Go to the documentation of this file.
1
6#pragma once
7#ifndef SCANBOTSDK_HPP
8#define SCANBOTSDK_HPP
9
10#include <array>
11#include <string>
12#include <vector>
13#include <iostream>
14
15#include <ScanbotSDK.h>
16
17
18namespace scanbotsdk {
19
23 std::string text;
38 std::array<int, 8> quad;
40 std::vector<unsigned char> rawBytes;
41};
42
43struct InitParams {
44 std::string licenseKey;
45};
46
53static scanbotsdk_error_code_t initialize(const InitParams& params) {
54 scanbotsdk_init_params_t initParams = {};
55 initParams.license_key = params.licenseKey.c_str();
56 return scanbotsdk_initialize(&initParams);
57}
58
62static scanbotsdk_license_status_t getLicenseStatus() {
65 return status;
66}
67
72 public:
73
81 std::vector<scanbotsdk_barcode_format_t> formats;
88 bool useTensorRT = false;
95 };
96
103
105 .formats = params.formats.data(),
106 .formats_count = static_cast<int>(params.formats.size()),
107 .use_tensorrt = params.useTensorRT,
108 .tensorrt_max_input_width = params.tensorrtMaxInputWidth,
109 .tensorrt_max_input_height = params.tensorrtMaxInputHeight,
110 .tensorrt_max_workspace_size = params.tensorrtMaxWorkspaceSize
111 };
112
113 auto ret = scanbotsdk_barcode_recognizer_create(&init_params, &recognizer);
114 if (ret != scanbotsdk_error_code_t::SCANBOTSDK_OK) {
115 recognizer = nullptr;
116 }
117 }
118
120 if (recognizer != nullptr){
122 }
123 }
124
130 std::vector<BarCodeItem> recognize(scanbotsdk_image_t image){
131
132 if (recognizer == nullptr){
133 scanbotsdk_log_error("Aborted due to invalid recognizer state.");
134 return {};
135 }
136
137 scanbotsdk_barcode_result_t* barcode_result = nullptr;
138 auto ret = scanbotsdk_barcode_recognizer_recognize(recognizer, &image, &barcode_result);
139 if (ret != SCANBOTSDK_OK) {
140 return {};
141 }
142
143 std::vector<BarCodeItem> retval;
144 int count = 0;
145 if (scanbotsdk_barcode_result_get_count(barcode_result, &count) != SCANBOTSDK_OK) {
146 return {};
147 }
148
149 for (int barcode_idx = 0; barcode_idx < count; barcode_idx++) {
150 BarCodeItem item;
151
152 const char* cText = nullptr;
153 if (scanbotsdk_barcode_result_get_text(barcode_result, barcode_idx, &cText) != SCANBOTSDK_OK) {
154 return {};
155 }
156
157 item.text = std::string(cText);
158
159 int rawBytesLength = 0;
160 const unsigned char* cRawBytes = nullptr;
161 if(scanbotsdk_barcode_result_get_raw_bytes(barcode_result, barcode_idx,
162 &cRawBytes, &rawBytesLength) != SCANBOTSDK_OK) {
163 return {};
164 }
165 item.rawBytes = std::vector<unsigned char>(cRawBytes, cRawBytes + rawBytesLength);
166
167 if (scanbotsdk_barcode_result_get_format(barcode_result, barcode_idx,
168 &item.format) != SCANBOTSDK_OK) {
169 return {};
170 }
171
172 if(scanbotsdk_barcode_result_get_quad(barcode_result, barcode_idx, item.quad.data()) != SCANBOTSDK_OK) {
173 return {};
174 }
175
176 retval.push_back(item);
177 }
178
179 if (scanbotsdk_barcode_result_free(barcode_result)!=SCANBOTSDK_OK) {
180 return {};
181 }
182
183 return retval;
184 }
185
186 private:
187 scanbotsdk_barcode_recognizer_t* recognizer = nullptr;
188};
189
190} // namespace scanbotsdk::barcode
191#endif // SCANBOTSDK_HPP
The Scanbot SDK C API.
scanbotsdk_error_code_t
The error codes returned by most of the Scanbot SDK functions.
Definition ScanbotSDK.h:30
@ SCANBOTSDK_OK
Definition ScanbotSDK.h:32
The barcode recognizer is capable of detecting and decoding barcodes in images.
Definition ScanbotSDK.hpp:71
BarcodeRecognizer(const BarcodeRecognizer::InitializationParams &params)
Creates a new barcode recognizer.
Definition ScanbotSDK.hpp:102
std::vector< BarCodeItem > recognize(scanbotsdk_image_t image)
Recognizes barcodes in the given image.
Definition ScanbotSDK.hpp:130
scanbotsdk_barcode_engine_mode_t engine_mode
The barcode recognition engine mode.
Definition ScanbotSDK.h:151
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_get_text(const scanbotsdk_barcode_result_t *result, int index, const char **text)
Returns the barcode text as a null-terminated UTF8-encoded string of the given barcode in a result.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_get_format(const scanbotsdk_barcode_result_t *result, int index, scanbotsdk_barcode_format_t *format)
Returns the barcode format of a the given barcode in a result.
scanbotsdk_barcode_engine_mode_t
Barcode recognition engine modes.
Definition ScanbotSDK.h:114
struct scanbotsdk_barcode_result_t scanbotsdk_barcode_result_t
Represents the result of a call to scanbotsdk_barcode_recognizer_recognize.
Definition ScanbotSDK.h:213
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_recognizer_free(scanbotsdk_barcode_recognizer_t *recognizer)
Destroys the barcode recognizer instance.
scanbotsdk_barcode_format_t
Barcode format, also called symbology.
Definition ScanbotSDK.h:79
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_get_count(const scanbotsdk_barcode_result_t *result, int *count)
Returns the count of detected barcodes in a result.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_free(scanbotsdk_barcode_result_t *result)
Destroys the barcode result instance.
struct scanbotsdk_barcode_recognizer_t scanbotsdk_barcode_recognizer_t
Represents an instance of the barcode recognizer.
Definition ScanbotSDK.h:207
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_recognizer_create(const scanbotsdk_barcode_recognizer_init_params_t *params, scanbotsdk_barcode_recognizer_t **recognizer)
Creates a new instance of the barcode recognizer.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_get_raw_bytes(const scanbotsdk_barcode_result_t *result, int index, const unsigned char **raw_bytes, int *length)
Returns the raw bytes of a given barcode from the result.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_result_get_quad(const scanbotsdk_barcode_result_t *result, int barcode_index, int *quad)
Returns the coordinates in pixel space of the four corners of a given barcode in the result.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_barcode_recognizer_recognize(scanbotsdk_barcode_recognizer_t *recognizer, const scanbotsdk_image_t *input, scanbotsdk_barcode_result_t **result)
Recognize barcodes in an image.
@ SCANBOTSDK_BARCODE_ENGINE_MODE_BALANCED
Single-shot recognition mode for static images.
Definition ScanbotSDK.h:136
Barcode recognizer initialization parameters.
Definition ScanbotSDK.h:149
scanbotsdk_license_status_t
The status of the license.
Definition ScanbotSDK.h:58
SBSDK_API scanbotsdk_error_code_t scanbotsdk_get_license_status(scanbotsdk_license_status_t *status)
Returns the current license status.
SBSDK_API scanbotsdk_error_code_t scanbotsdk_initialize(const scanbotsdk_init_params_t *init_params)
Initialize the Scanbot SDK. You must always call this function before using any other Scanbot SDK fun...
SBSDK_API scanbotsdk_error_code_t scanbotsdk_log_error(const char *message)
Logs an error message using the Scanbot SDK logger.
Contains the information about a single barcode.
Definition ScanbotSDK.hpp:21
std::string text
The barcode data as text.
Definition ScanbotSDK.hpp:23
scanbotsdk_barcode_format_t format
The barcode format, also called its symbology.
Definition ScanbotSDK.hpp:25
std::vector< unsigned char > rawBytes
The barcode data as raw bytes.
Definition ScanbotSDK.hpp:40
std::array< int, 8 > quad
The coordinates of the barcode's quadrangle in the image.
Definition ScanbotSDK.hpp:38
The initialization parameters for the barcode recognizer.
Definition ScanbotSDK.hpp:77
std::vector< scanbotsdk_barcode_format_t > formats
The barcode formats to detect. If empty, all formats will be recognized.
Definition ScanbotSDK.hpp:81
size_t tensorrtMaxWorkspaceSize
The maximum workspace size in bytes for TensorRT. If 0, the default value will be used.
Definition ScanbotSDK.hpp:94
bool useTensorRT
If true, the barcode recognizer will use the TensorRT backend for GPU acceleration.
Definition ScanbotSDK.hpp:88
int tensorrtMaxInputWidth
The maximum input width in pixels for TensorRT. If 0, the default value will be used.
Definition ScanbotSDK.hpp:90
scanbotsdk_barcode_engine_mode_t engineMode
The barcode recognition engine mode.
Definition ScanbotSDK.hpp:79
int tensorrtMaxInputHeight
The maximum input height in pixels for TensorRT. If 0, the default value will be used.
Definition ScanbotSDK.hpp:92
Definition ScanbotSDK.hpp:43
Wrapper for image data.
Definition ScanbotSDK.h:185
Definition ScanbotSDK.h:215