This example uses the Scandit SDK to detect barcodes in frames from a camera.
This demo is currently limited to GNU/Linux systems with a Video4Linux 2 camera.
On slow hardware platforms like the Raspberry 2, 3 or Zero we recommend the following change to the sample: Set the define LOW_END_DEVICE_CONFIGURATION to 1 and run the sample with a resolution of 640x480.
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#define SCANDIT_SDK_LICENSE_KEY "-- INSERT YOUR LICENSE KEY HERE --"
#define DEFAULT_RESOLUTION_WIDTH 1280
#define DEFAULT_RESOLUTION_HEIGHT 720
#define LOW_END_DEVICE_CONFIGURATION 0
static volatile ScBool process_frames;
static void catch_exit(int signo) {
printf("SIGINT received.\n");
}
static void print_all_discrete_resolutions(
const ScCamera *cam) {
printf("This camera uses discrete resolutions:\n");
for (int32_t i = 0; i < resolution_count; i++) {
for (int32_t j = 0; j < framerate_count; j++) {
printf("\t%u:%u @ %.2f FPS\n", resolution_array[i].width, resolution_array[i].height, fps);
}
}
}
int main(int argc, const char *argv[]) {
if (signal(SIGINT, catch_exit) == SIG_ERR) {
printf("Could not set up signal handler.\n");
return -1;
}
if (argc > 1) {
} else {
}
if (camera == NULL) {
printf("No camera available.\n");
return -1;
}
uint32_t resolution_width = DEFAULT_RESOLUTION_WIDTH;
uint32_t resolution_height = DEFAULT_RESOLUTION_HEIGHT;
if (argc == 4) {
resolution_width = atoi(argv[2]);
resolution_height = atoi(argv[3]);
}
const uint32_t resolutions_size = 30;
ScSize resolutions[resolutions_size];
int32_t resolutions_found;
switch (resm) {
print_all_discrete_resolutions(camera);
if (!resolutions_found) {
printf("There was an error getting the discrete resolution capabilities of the camera.\n");
return -1;
}
for (int i = 0; i < resolutions_found; i++) {
if (resolutions[i].width == resolution_width &&
resolutions[i].height == resolution_height) {
break;
}
}
break;
printf("There was an error getting the stepwise resolution capabilities of the camera.\n");
return -1;
}
printf("This camera uses step-wise resolutions:\n");
}
break;
default:
printf("Could not get camera resolution mode.\n");
return -1;
}
if (!supported) {
printf("%dx%d is not supported by this camera.\nPlease specify a supported resolution on the command line or in the source code.\n", resolution_width, resolution_height);
return -1;
}
desired_resolution.
width = resolution_width;
desired_resolution.
height = resolution_height;
printf("Setting resolution failed.\n");
return -1;
}
printf("Start the camera failed.\n");
return -1;
}
if (context == NULL) {
printf("Could not initialize context.\n");
return -1;
}
if (settings == NULL) {
return -1;
}
.size.width = 1.0f, .size.height = 0.2f };
#if LOW_END_DEVICE_CONFIGURATION
#else
#endif
if (scanner == NULL) {
return -1;
}
while (process_frames) {
if (image_data == NULL) {
printf("Frame access failed. Exiting.\n");
break;
}
printf(
"Processing frame failed with error %d: '%s'\n", result.
status,
}
for (int i = 0; i < code_count; i++) {
printf("Barcode found: '%s'\n", data.str);
}
}
}