Scanbot SDK
Loading...
Searching...
No Matches
ScanbotSDK.hpp
1//
2//
3//#pragma once
4//#ifndef SCANBOTSDK_HPP
5//#define SCANBOTSDK_HPP
6//
7//#include <array>
8//#include <string>
9//#include <vector>
10//#include <iostream>
11//
12//#include <ScanbotSDK.h>
13//
14//
15//namespace scanbotsdk {
16//
18//struct BarcodeItem {
19// /// The barcode data as text.
20// std::string text;
21// /// The barcode format, also called its symbology.
22// scanbotsdk_barcode_format_t format;
23// /**
24// * @brief The coordinates of the barcode's quadrangle in the image.
25// * @details The coordinates are returned in the following order:
26// * - 0 : top-left-x,
27// * - 1 : top-left-y,
28// * - 2 : top-right-x,
29// * - 3 : top-right-y,
30// * - 4 : bottom-right-x,
31// * - 5 : bottom-right-y,
32// * - 6 : bottom-left-x,
33// * - 7 : bottom-left-y
34// */
35// std::array<int, 8> quad;
36// /// The barcode data as raw bytes.
37// std::vector<unsigned char> rawBytes;
38//};
39//
41// * @brief The initialization parameters for the Scanbot SDK.
42// */
43//struct InitParams {
44// /// The license key.
45// std::string licenseKey;
46//};
47//
49// * @brief Initialize the Scanbot SDK. You must call this function once before using any other Scanbot SDK
50// * functions.
51// * @param params: The initialization parameters. You must provide a valid license key.
52// * @return: Error code, <see cref="SCANBOTSDK_OK"/> if initialization was successful.
53// */
54//static scanbotsdk_error_code_t initialize(const InitParams& params) {
55// scanbotsdk_init_params_t initParams = {};
56// initParams.license_key = params.licenseKey.c_str();
57// return scanbotsdk_initialize(&initParams);
58//}
59//
61// * @brief Returns the current license status.
62// */
63//static scanbotsdk_license_status_t getLicenseStatus() {
64// scanbotsdk_license_status_t status;
65// scanbotsdk_get_license_status(&status);
66// return status;
67//}
68//
70// * @brief The barcode recognizer is capable of detecting and decoding barcodes in images.
71// */
72//class BarcodeRecognizer {
73// public:
74//
75// /**
76// * @brief The initialization parameters for the barcode recognizer.
77// */
78// struct InitializationParams{
79// /** @brief The barcode recognition image schedule type mode. */
80// scanbotsdk_barcode_engine_mode_t engine_mode = SCANBOTSDK_BARCODE_ENGINE_MODE_NEXT_GEN;
81// /** @brief If the barcode recognition is performed in tryHarderMode. */
82// bool is_live = false;
83// /** @brief The barcode formats to detect. If empty, all formats will be recognized */
84// std::vector<scanbotsdk_barcode_format_t> formats;
85// /**
86// * @brief If true, the barcode recognizer will use the TensorRT backend for GPU acceleration.
87// * @details When enabling TensorRT, use the smallest input image size that fits your use case. The bigger the image size, the more memory is
88// * required at runtime. It takes around 3 minutes to build the TensorRT engine for the first time. The engine is then cached on disk and reused.
89// * The cached engine can be copied to other devices with the same device model, Jetpack version, CUDA version and TensorRT version.
90// */
91// bool useTensorRT = false;
92// /** @brief The maximum input width in pixels for TensorRT. If 0, the default value will be used. */
93// int tensorrtMaxInputWidth = 0;
94// /** @brief The maximum input height in pixels for TensorRT. If 0, the default value will be used. */
95// int tensorrtMaxInputHeight = 0;
96// /** @brief The maximum workspace size in bytes for TensorRT. If 0, the default value will be used. */
97// size_t tensorrtMaxWorkspaceSize = 0;
98// };
99//
100// /**
101// * @brief Creates a new barcode recognizer.
102// * @param params: The initialization parameters.
103// */
104// BarcodeRecognizer(const BarcodeRecognizer::InitializationParams& params) {
105//
106// scanbotsdk_barcode_scanner_init_params_t init_params = {.engine_mode = params.engine_mode,
107// .is_live = params.is_live,
108// .formats = params.formats.data(),
109// .formats_count = static_cast<int>(params.formats.size()),
110// .use_tensorrt = params.useTensorRT,
111// .tensorrt_max_input_width = params.tensorrtMaxInputWidth,
112// .tensorrt_max_input_height = params.tensorrtMaxInputHeight,
113// .tensorrt_max_workspace_size = params.tensorrtMaxWorkspaceSize
114// };
115//
116// auto ret = scanbotsdk_barcode_scanner_create(&init_params, &recognizer);
117// if (ret != scanbotsdk_error_code_t::SCANBOTSDK_OK) {
118// recognizer = nullptr;
119// }
120// }
121//
122// ~BarcodeRecognizer() {
123// if (recognizer != nullptr){
124// scanbotsdk_barcode_scanner_free(recognizer);
125// }
126// }
127//
128// /**
129// * @brief Recognizes barcodes in the given image.
130// * @param image: The image to recognize barcodes in.
131// * @return: A list of recognized barcodes.
132// */
133// std::vector<BarcodeItem> recognize(scanbotsdk_image_t image){
134//
135// if (recognizer == nullptr){
136// scanbotsdk_log_error("Aborted due to invalid recognizer state.");
137// return {};
138// }
139//
140// scanbotsdk_barcode_result_t* barcode_result = nullptr;
141// auto ret = scanbotsdk_barcode_scanner_scan(recognizer, &image, &barcode_result);
142// if (ret != SCANBOTSDK_OK) {
143// return {};
144// }
145//
146// std::vector<BarcodeItem> retval;
147// int count = 0;
148// if (scanbotsdk_barcode_result_get_count(barcode_result, &count) != SCANBOTSDK_OK) {
149// return {};
150// }
151//
152// for (int barcode_idx = 0; barcode_idx < count; barcode_idx++) {
153// BarcodeItem item;
154//
155// const char* cText = nullptr;
156// if (scanbotsdk_barcode_result_get_text(barcode_result, barcode_idx, &cText) != SCANBOTSDK_OK) {
157// return {};
158// }
159//
160// item.text = std::string(cText);
161//
162// int rawBytesLength = 0;
163// const unsigned char* cRawBytes = nullptr;
164// if(scanbotsdk_barcode_result_get_raw_bytes(barcode_result, barcode_idx,
165// &cRawBytes, &rawBytesLength) != SCANBOTSDK_OK) {
166// return {};
167// }
168// item.rawBytes = std::vector<unsigned char>(cRawBytes, cRawBytes + rawBytesLength);
169//
170// if (scanbotsdk_barcode_result_get_format(barcode_result, barcode_idx,
171// &item.format) != SCANBOTSDK_OK) {
172// return {};
173// }
174//
175// if(scanbotsdk_barcode_result_get_quad(barcode_result, barcode_idx, item.quad.data()) != SCANBOTSDK_OK) {
176// return {};
177// }
178//
179// retval.push_back(item);
180// }
181//
182// if (scanbotsdk_barcode_result_free(barcode_result)!=SCANBOTSDK_OK) {
183// return {};
184// }
185//
186// return retval;
187// }
188//
189// private:
190// scanbotsdk_barcode_scanner_t* recognizer = nullptr;
191//};
192//
193//} // namespace scanbotsdk::barcode
194//#endif // SCANBOTSDK_HPP