Skip to content

Commit 059fb0d

Browse files
Kyrylocyrillicw
authored andcommitted
Add tensorrt support
1 parent 6519411 commit 059fb0d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

examples/c/barcode/live/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ You should provide it with the image you want to be used as a camera frame.
88
## Usage
99
```bash
1010
<build_directory>/barcode/live/barcode_live <license_key> <image_path>
11+
```
12+
13+
In order to run with TensorRT support, you can use the `--use-tensor-rt` flag:
14+
15+
```bash
16+
<build_directory>/barcode/live/barcode_live <license_key> <image_path> --use-tensor-rt
1117
```

examples/c/barcode/live/main.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <string.h>
4+
#include <unistd.h>
5+
#include <limits.h>
46
#include <ScanbotSDK.h>
57

68
const char *error_message(scanbotsdk_error_code_t ec) {
@@ -123,10 +125,11 @@ scanbotsdk_error_code_t process_frame(scanbotsdk_barcode_scanner_t *scanner, fra
123125
return ec;
124126
}
125127

126-
scanbotsdk_error_code_t create_barcode_scanner(scanbotsdk_barcode_scanner_t **barcode_scanner) {
128+
scanbotsdk_error_code_t create_barcode_scanner(bool use_tensor_rt, scanbotsdk_barcode_scanner_t **barcode_scanner) {
127129
scanbotsdk_error_code_t ec = SCANBOTSDK_OK;
128130

129131
scanbotsdk_barcode_format_common_configuration_t *common_format_configuration = NULL;
132+
scanbotsdk_accelerator_t* accelerator = NULL;
130133
scanbotsdk_barcode_scanner_configuration_t *barcode_scanner_configuration = NULL;
131134

132135
// region create barcode scanner configuration
@@ -168,6 +171,19 @@ scanbotsdk_error_code_t create_barcode_scanner(scanbotsdk_barcode_scanner_t **ba
168171
if (ec != SCANBOTSDK_OK) {
169172
goto exit;
170173
}
174+
175+
if (use_tensor_rt) {
176+
scanbotsdk_tensor_rt_accelerator_t *tensor_rt_accelerator = NULL;
177+
ec = scanbotsdk_tensor_rt_accelerator_create("./", &tensor_rt_accelerator);
178+
if (ec != SCANBOTSDK_OK) {
179+
goto exit;
180+
}
181+
scanbotsdk_tensor_rt_accelerator_as_scanbotsdk_accelerator(tensor_rt_accelerator, &accelerator);
182+
ec = scanbotsdk_barcode_scanner_configuration_set_accelerator(barcode_scanner_configuration, accelerator);
183+
if (ec != SCANBOTSDK_OK) {
184+
goto exit;
185+
}
186+
}
171187
// endregion
172188

173189
// region create barcode scanner
@@ -178,8 +194,9 @@ scanbotsdk_error_code_t create_barcode_scanner(scanbotsdk_barcode_scanner_t **ba
178194
// endregion
179195

180196
exit:
181-
scanbotsdk_barcode_format_common_configuration_free(common_format_configuration);
182197
scanbotsdk_barcode_scanner_configuration_free(barcode_scanner_configuration);
198+
scanbotsdk_accelerator_free(accelerator);
199+
scanbotsdk_barcode_format_common_configuration_free(common_format_configuration);
183200
return ec;
184201
}
185202

@@ -189,6 +206,13 @@ int main(int argc, char *argv[]) {
189206
return 1;
190207
}
191208

209+
bool use_tensor_rt = false;
210+
if (argc > 3) {
211+
if (strcmp(argv[3], "--use-tensor-rt") == 0) {
212+
use_tensor_rt = true;
213+
}
214+
}
215+
192216
const int initialization_timeout_ms = 15000;
193217
const int deregister_device_timeout_ms = 15000;
194218

@@ -218,7 +242,7 @@ int main(int argc, char *argv[]) {
218242
// endregion
219243

220244
// region create barcode scanner
221-
ec = create_barcode_scanner(&barcode_scanner);
245+
ec = create_barcode_scanner(use_tensor_rt, &barcode_scanner);
222246
if (ec != SCANBOTSDK_OK) {
223247
fprintf(stderr, "Failed to create barcode scanner: %d: %s\n", ec, error_message(ec));
224248
goto exit;

0 commit comments

Comments
 (0)