diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/codabar.png | bin | 0 -> 198 bytes | |||
-rw-r--r-- | examples/code-128.png | bin | 0 -> 2575 bytes | |||
-rw-r--r-- | examples/code-39.png | bin | 0 -> 2091 bytes | |||
-rw-r--r-- | examples/code-93.png | bin | 0 -> 1943 bytes | |||
-rw-r--r-- | examples/code-upc-a.png | bin | 0 -> 1040 bytes | |||
-rw-r--r-- | examples/databar-exp.png | bin | 0 -> 199 bytes | |||
-rw-r--r-- | examples/databar.png | bin | 0 -> 1774 bytes | |||
-rw-r--r-- | examples/ean-13.png | bin | 0 -> 1041 bytes | |||
-rw-r--r-- | examples/ean-2.png | bin | 0 -> 132 bytes | |||
-rw-r--r-- | examples/ean-5.png | bin | 0 -> 179 bytes | |||
-rw-r--r-- | examples/ean-8.png | bin | 0 -> 1503 bytes | |||
-rw-r--r-- | examples/i2-5.png | bin | 0 -> 1564 bytes | |||
-rw-r--r-- | examples/processor.c | 47 | ||||
-rw-r--r-- | examples/processor.cpp | 44 | ||||
-rw-r--r-- | examples/qr-code-binary.png | bin | 0 -> 922 bytes | |||
-rw-r--r-- | examples/qr-code-inverted.png | bin | 0 -> 14309 bytes | |||
-rw-r--r-- | examples/qr-code.png | bin | 0 -> 210 bytes | |||
-rw-r--r-- | examples/scan_image.c | 117 | ||||
-rw-r--r-- | examples/scan_image.cpp | 56 | ||||
-rw-r--r-- | examples/scan_image.vcproj | 46 | ||||
-rw-r--r-- | examples/sha1sum | 19 | ||||
-rw-r--r-- | examples/sqcode1-generated.png | bin | 0 -> 4254 bytes | |||
-rw-r--r-- | examples/sqcode1-scanned.png | bin | 0 -> 339859 bytes | |||
-rwxr-xr-x | examples/upcrpc.pl | 46 | ||||
-rwxr-xr-x | examples/upcrpc.py | 50 |
25 files changed, 425 insertions, 0 deletions
diff --git a/examples/codabar.png b/examples/codabar.png Binary files differnew file mode 100644 index 0000000..3482a31 --- /dev/null +++ b/examples/codabar.png diff --git a/examples/code-128.png b/examples/code-128.png Binary files differnew file mode 100644 index 0000000..d8b8845 --- /dev/null +++ b/examples/code-128.png diff --git a/examples/code-39.png b/examples/code-39.png Binary files differnew file mode 100644 index 0000000..2b0fbc8 --- /dev/null +++ b/examples/code-39.png diff --git a/examples/code-93.png b/examples/code-93.png Binary files differnew file mode 100644 index 0000000..83a65b1 --- /dev/null +++ b/examples/code-93.png diff --git a/examples/code-upc-a.png b/examples/code-upc-a.png Binary files differnew file mode 100644 index 0000000..992a49c --- /dev/null +++ b/examples/code-upc-a.png diff --git a/examples/databar-exp.png b/examples/databar-exp.png Binary files differnew file mode 100644 index 0000000..7091be4 --- /dev/null +++ b/examples/databar-exp.png diff --git a/examples/databar.png b/examples/databar.png Binary files differnew file mode 100644 index 0000000..23dc6c6 --- /dev/null +++ b/examples/databar.png diff --git a/examples/ean-13.png b/examples/ean-13.png Binary files differnew file mode 100644 index 0000000..ac6dd0b --- /dev/null +++ b/examples/ean-13.png diff --git a/examples/ean-2.png b/examples/ean-2.png Binary files differnew file mode 100644 index 0000000..5ec2983 --- /dev/null +++ b/examples/ean-2.png diff --git a/examples/ean-5.png b/examples/ean-5.png Binary files differnew file mode 100644 index 0000000..2c3d039 --- /dev/null +++ b/examples/ean-5.png diff --git a/examples/ean-8.png b/examples/ean-8.png Binary files differnew file mode 100644 index 0000000..d1cc3a8 --- /dev/null +++ b/examples/ean-8.png diff --git a/examples/i2-5.png b/examples/i2-5.png Binary files differnew file mode 100644 index 0000000..7d46fdc --- /dev/null +++ b/examples/i2-5.png diff --git a/examples/processor.c b/examples/processor.c new file mode 100644 index 0000000..773440e --- /dev/null +++ b/examples/processor.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <zbar.h> + +static void my_handler(zbar_image_t *image, const void *userdata) +{ + /* extract results */ + const zbar_symbol_t *symbol = zbar_image_first_symbol(image); + + for (; symbol; symbol = zbar_symbol_next(symbol)) { + /* do something useful with results */ + zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); + const char *data = zbar_symbol_get_data(symbol); + + printf("decoded %s symbol \"%s\"\n", zbar_get_symbol_name(typ), data); + } +} + +int main(int argc, char **argv) +{ + const char *device = "/dev/video0"; + + /* create a Processor */ + zbar_processor_t *proc = zbar_processor_create(1); + + /* configure the Processor */ + zbar_processor_set_config(proc, 0, ZBAR_CFG_ENABLE, 1); + + /* initialize the Processor */ + if (argc > 1) + device = argv[1]; + zbar_processor_init(proc, device, 1); + + /* setup a callback */ + zbar_processor_set_data_handler(proc, my_handler, NULL); + + /* enable the preview window */ + zbar_processor_set_visible(proc, 1); + zbar_processor_set_active(proc, 1); + + /* keep scanning until user provides key/mouse input */ + zbar_processor_user_wait(proc, -1); + + /* clean up */ + zbar_processor_destroy(proc); + + return (0); +} diff --git a/examples/processor.cpp b/examples/processor.cpp new file mode 100644 index 0000000..a032a5b --- /dev/null +++ b/examples/processor.cpp @@ -0,0 +1,44 @@ +#include <iostream> +#include <zbar.h> + +using namespace std; +using namespace zbar; + +class MyHandler : public Image::Handler +{ + void image_callback(Image &image) + { + for (SymbolIterator symbol = image.symbol_begin(); + symbol != image.symbol_end(); ++symbol) + cout << "decoded " << symbol->get_type_name() << " symbol " + << "\"" << symbol->get_data() << "\"" << endl; + } +}; + +int main(int argc, char **argv) +{ + // create and initialize a Processor + const char *device = "/dev/video0"; + + if (argc > 1) + device = argv[1]; + Processor proc(true, device); + + // configure the Processor + proc.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + + // setup a callback + MyHandler my_handler; + proc.set_handler(my_handler); + + // enable the preview window + proc.set_visible(); + proc.set_active(); + + try { + // keep scanning until user provides key/mouse input + proc.user_wait(); + } catch (ClosedError &e) { + } + return (0); +} diff --git a/examples/qr-code-binary.png b/examples/qr-code-binary.png Binary files differnew file mode 100644 index 0000000..6337d26 --- /dev/null +++ b/examples/qr-code-binary.png diff --git a/examples/qr-code-inverted.png b/examples/qr-code-inverted.png Binary files differnew file mode 100644 index 0000000..79c46d3 --- /dev/null +++ b/examples/qr-code-inverted.png diff --git a/examples/qr-code.png b/examples/qr-code.png Binary files differnew file mode 100644 index 0000000..bd04229 --- /dev/null +++ b/examples/qr-code.png diff --git a/examples/scan_image.c b/examples/scan_image.c new file mode 100644 index 0000000..a44b58c --- /dev/null +++ b/examples/scan_image.c @@ -0,0 +1,117 @@ +#include <png.h> +#include <stdio.h> +#include <stdlib.h> +#include <zbar.h> + +#if !defined(PNG_LIBPNG_VER) || PNG_LIBPNG_VER < 10018 || \ + (PNG_LIBPNG_VER > 10200 && PNG_LIBPNG_VER < 10209) +/* Changes to Libpng from version 1.2.42 to 1.4.0 (January 4, 2010) + * ... + * 2. m. The function png_set_gray_1_2_4_to_8() was removed. It has been + * deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with + * png_set_expand_gray_1_2_4_to_8() because the former function also + * expanded palette images. + */ +#define png_set_expand_gray_1_2_4_to_8 png_set_gray_1_2_4_to_8 +#endif + +zbar_image_scanner_t *scanner = NULL; + +/* to complete a runnable example, this abbreviated implementation of + * get_data() will use libpng to read an image file. refer to libpng + * documentation for details + */ +static void get_data(const char *name, int *width, int *height, void **raw) +{ + png_structp png; + png_infop info; + int color, bits; + png_bytep *rows; + int i; + FILE *file = fopen(name, "rb"); + + if (!file) + exit(2); + png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png) + exit(3); + if (setjmp(png_jmpbuf(png))) + exit(4); + info = png_create_info_struct(png); + if (!info) + exit(5); + png_init_io(png, file); + png_read_info(png, info); + /* configure for 8bpp grayscale input */ + color = png_get_color_type(png, info); + bits = png_get_bit_depth(png, info); + if (color & PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png); + if (color == PNG_COLOR_TYPE_GRAY && bits < 8) + png_set_expand_gray_1_2_4_to_8(png); + if (bits == 16) + png_set_strip_16(png); + if (color & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png); + if (color & PNG_COLOR_MASK_COLOR) + png_set_rgb_to_gray_fixed(png, 1, -1, -1); + + /* allocate image */ + *width = png_get_image_width(png, info); + *height = png_get_image_height(png, info); + *raw = (png_bytep)calloc(*width * *height, sizeof(png_byte)); + rows = (png_bytep *)calloc(*height, sizeof(*rows)); + + for (i = 0; i < *height; i++) + rows[i] = ((png_bytep)(*raw)) + (*width * i); + + png_read_image(png, rows); + free(rows); +} + +int main(int argc, char **argv) +{ + int width, height, n; + void *raw; + zbar_image_t *image; + const zbar_symbol_t *symbol; + + if (argc < 2) + return (1); + + /* create a reader */ + scanner = zbar_image_scanner_create(); + + /* configure the reader */ + zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); + + /* obtain image data */ + width = 0, height = 0; + raw = NULL; + get_data(argv[1], &width, &height, &raw); + + /* wrap image data */ + image = zbar_image_create(); + zbar_image_set_format(image, zbar_fourcc('Y', '8', '0', '0')); + zbar_image_set_size(image, width, height); + zbar_image_set_data(image, raw, width * height, zbar_image_free_data); + + /* scan the image for barcodes */ + n = zbar_scan_image(scanner, image); + + /* extract results */ + symbol = zbar_image_first_symbol(image); + for (; symbol; symbol = zbar_symbol_next(symbol)) { + /* do something useful with results */ + zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); + const char *data = zbar_symbol_get_data(symbol); + + printf("decoded %s symbol \"%s\"\n", zbar_get_symbol_name(typ), data); + } + + /* clean up */ + zbar_image_destroy(image); + zbar_image_scanner_destroy(scanner); + + return (0); +} diff --git a/examples/scan_image.cpp b/examples/scan_image.cpp new file mode 100644 index 0000000..55f5c32 --- /dev/null +++ b/examples/scan_image.cpp @@ -0,0 +1,56 @@ +#include <Magick++.h> +#include <iostream> +#include <zbar.h> +#define STR(s) #s + +using namespace std; +using namespace zbar; + +int main(int argc, char **argv) +{ + if (argc < 2) + return (1); + +#ifdef MAGICK_HOME + // http://www.imagemagick.org/Magick++/ + // under Windows it is necessary to initialize the ImageMagick + // library prior to using the Magick++ library + Magick::InitializeMagick(MAGICK_HOME); +#endif + + // create a reader + ImageScanner scanner; + + // configure the reader + scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + + // obtain image data + Magick::Image magick(argv[1]); // read an image file + + int width = magick.columns(); // extract dimensions + int height = magick.rows(); + + Magick::Blob blob; // extract the raw data + magick.modifyImage(); + magick.write(&blob, "GRAY", 8); + const void *raw = blob.data(); + + // wrap image data + Image image(width, height, "Y800", raw, width * height); + + // scan the image for barcodes + int n = scanner.scan(image); + + // extract results + for (Image::SymbolIterator symbol = image.symbol_begin(); + symbol != image.symbol_end(); ++symbol) { + // do something useful with results + cout << "decoded " << symbol->get_type_name() << " symbol \"" + << symbol->get_data() << '"' << endl; + } + + // clean up + image.set_data(NULL, 0); + + return (0); +} diff --git a/examples/scan_image.vcproj b/examples/scan_image.vcproj new file mode 100644 index 0000000..37937de --- /dev/null +++ b/examples/scan_image.vcproj @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="scan_image" + RootNamespace="scan_image" + Keyword="Win32Proj"> + + <Platforms> + <Platform Name="Win32"/> + </Platforms> + + <Configurations> + <Configuration + Name="Debug|Win32" + ConfigurationType="1"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\include;"C:\Program Files\ImageMagick-6.5.4-Q16\include"" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;"MAGICK_HOME=STR(C:\\Program Files\\ImageMagick-6.5.4-Q16)"" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="4" + WarnAsError="true" + DisableSpecificWarnings="4100;4189;4251" + DebugInformationFormat="4"/> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="..\lib\libzbar-0.lib kernel32.lib "C:\Program Files\ImageMagick-6.5.4-Q16\lib\CORE_RL_Magick++_.lib" $(NoInherit)" + ShowProgress="0" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1"/> + </Configuration> + </Configurations> + + <Files> + <Filter + Name="Source Files" + Filter="cpp"> + <File RelativePath=".\scan_image.cpp"/> + </Filter> + </Files> + +</VisualStudioProject> diff --git a/examples/sha1sum b/examples/sha1sum new file mode 100644 index 0000000..72cab2e --- /dev/null +++ b/examples/sha1sum @@ -0,0 +1,19 @@ +a56811d078ea5cfac9be5deb4b6796177763e152 zbarimg codabar.png +cc53bf34878f769fc3611020c11e572f2853bd2a zbarimg code-128.png +7537d593ea42393a43bc0eda0a896c0e31017dd8 zbarimg code-39.png +f8f55b828eb7d0400f300be021d29293bd4a3191 zbarimg code-93.png +aebbdbed0b32d7fd72f1245e3fb384822d492062 zbarimg databar.png +9e245874d3229a575eabfdba1c668369c55960e3 zbarimg databar-exp.png +53429fc04dfcf674349e2db6cfbaf73e301fc3dc zbarimg ean-13.png +4095418b74efbb026dd730543558fefdda46f5b9 zbarimg ean-8.png +5501245dbba21c153f690787fc97ab50c973b846 zbarimg i2-5.png +b350ca7efad7a50c5ac082d5c683a8e8d8d380a7 zbarimg qr-code.png +84c0ce7072e2227073dc8bd1e5f4518d8f42ae3d zbarimg sqcode1-generated.png +84c0ce7072e2227073dc8bd1e5f4518d8f42ae3d zbarimg sqcode1-scanned.png +5ab2b518e2c9d827cedc5825d2e3c9646d43713a zbarimg -Sean2.enable ean-2.png +668fef8cb9caac34df8cb8564c2cde62e4af5e65 zbarimg -Sean5.enable ean-5.png +b567e550216fe24f7652f683146365a9fe7ee867 zbarimg -Sisbn10.enable ean-13.png +d0f37aa076d42c270f7231c5490beea5605e2ba0 zbarimg -Sisbn13.enable ean-13.png +3f041225df3b8364b5fd0daf9cf402e8a4731f9b zbarimg -Supca.enable code-upc-a.png +b350ca7efad7a50c5ac082d5c683a8e8d8d380a7 zbarimg -Stest-inverted qr-code-inverted.png +df896e459e47a7d392031a7d4962722a143e276b zbarimg --raw --oneshot -Sbinary qr-code-binary.png diff --git a/examples/sqcode1-generated.png b/examples/sqcode1-generated.png Binary files differnew file mode 100644 index 0000000..323c45b --- /dev/null +++ b/examples/sqcode1-generated.png diff --git a/examples/sqcode1-scanned.png b/examples/sqcode1-scanned.png Binary files differnew file mode 100644 index 0000000..af831b5 --- /dev/null +++ b/examples/sqcode1-scanned.png diff --git a/examples/upcrpc.pl b/examples/upcrpc.pl new file mode 100755 index 0000000..5b0e10e --- /dev/null +++ b/examples/upcrpc.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Frontier::Client; +use Data::Dumper; +my $s = Frontier::Client->new('url' => 'http://www.upcdatabase.com/rpc'); + +$| = 1; # autoflush + +foreach (@ARGV) { + lookup($_); +} +if(!-t) { + while(1) { + my $decode = <STDIN>; + last unless(defined($decode)); + chomp($decode); + lookup($decode); + } +} + +sub lookup { + my $decode = shift; + if($decode =~ m[^(EAN-13:|UPC-A:)?(\d{11,13})$] && + ($1 && $1 eq "UPC-A:") || ($2 && length($2) > 11)) { + my $ean = $2; + $ean = "0" . $ean + if($1 && $1 eq "UPC-A:"); + $ean = $s->call('calculateCheckDigit', $ean . "C") + if(length($ean) == 12); + print("[$decode] "); + my $result = $s->call('lookupEAN', $s->string($ean)); + if(ref($result)) { + print((!$result->{found} || + (ref($result->{found}) && !$result->{found}->value())) + ? "not found\n" + : "$result->{description}\n") + } + else { + print("$result\n"); + } + } + else { + print("$decode\n"); + } +} diff --git a/examples/upcrpc.py b/examples/upcrpc.py new file mode 100755 index 0000000..5b0cd13 --- /dev/null +++ b/examples/upcrpc.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +from __future__ import print_function + +try: + from xmlrpc.client import ServerProxy +except: + from xmlrpclib import ServerProxy + +import sys, re + +server = ServerProxy("http://www.upcdatabase.com/rpc") +ean_re = re.compile(r'^(UPC-A:|EAN-13:)?(\d{11,13})$', re.M) + +def lookup(decode): + match = ean_re.search(decode) + if match is None: + print(decode, end=" ") + return + ean = match.group(2) + if match.group(1) == "UPC-A:": + ean = "0" + ean; + elif len(ean) < 12: + print(decode, end=' ') + return + if len(ean) == 12: + ean = server.calculateCheckDigit(ean + "C") + print("[" + match.group(1) + ean + "]", end=' ') + result = server.lookupEAN(ean) + if isinstance(result, dict): + if "found" not in result or not result["found"] or \ + "description" not in result: + print("not found") + else: + print(result["description"]) + else: + print(str(result)) + sys.stdout.flush() + +if __name__ == "__main__": + del sys.argv[0] + if len(sys.argv): + for decode in sys.argv: + lookup(decode) + if not sys.stdin.isatty(): + while 1: + decode = sys.stdin.readline() + if not decode: + break + lookup(decode) |