summaryrefslogtreecommitdiffstats
path: root/perl/examples/scan_image.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 00:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 00:06:44 +0000
commit44cf8ec67278bd1ab6c7f83a9993f7a5686a9541 (patch)
tree5eec4b0d1a3f163d279c3c27c03324ba49fa235a /perl/examples/scan_image.pl
parentInitial commit. (diff)
downloadzbar-44cf8ec67278bd1ab6c7f83a9993f7a5686a9541.tar.xz
zbar-44cf8ec67278bd1ab6c7f83a9993f7a5686a9541.zip
Adding upstream version 0.23.93.upstream/0.23.93upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'perl/examples/scan_image.pl')
-rwxr-xr-xperl/examples/scan_image.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/perl/examples/scan_image.pl b/perl/examples/scan_image.pl
new file mode 100755
index 0000000..39d460e
--- /dev/null
+++ b/perl/examples/scan_image.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+require Image::Magick;
+require Barcode::ZBar;
+
+$ARGV[0] || die;
+
+# create a reader
+my $scanner = Barcode::ZBar::ImageScanner->new();
+
+# configure the reader
+$scanner->parse_config("enable");
+
+# obtain image data
+my $magick = Image::Magick->new();
+$magick->Read($ARGV[0]) && die;
+my $raw = $magick->ImageToBlob(magick => 'GRAY', depth => 8);
+
+# wrap image data
+my $image = Barcode::ZBar::Image->new();
+$image->set_format('Y800');
+$image->set_size($magick->Get(qw(columns rows)));
+$image->set_data($raw);
+
+# scan the image for barcodes
+my $n = $scanner->scan_image($image);
+
+# extract results
+foreach my $symbol ($image->get_symbols()) {
+ # do something useful with results
+ print('decoded ' . $symbol->get_type() .
+ ' symbol "' . $symbol->get_data() . "\"\n");
+}
+
+# clean up
+undef($image);