summaryrefslogtreecommitdiffstats
path: root/examples/scan_image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scan_image.cpp')
-rw-r--r--examples/scan_image.cpp56
1 files changed, 56 insertions, 0 deletions
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);
+}