JeVoisBase  1.3
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
QRcode.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
19 #include <jevois/Debug/Log.H>
20 #include <jevois/Util/Utils.H>
21 
22 // ####################################################################################################
23 QRcode::QRcode(std::string const & instance) :
24  jevois::Component(instance), itsScanner(new zbar::ImageScanner())
25 {
26  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
27 }
28 
29 // ####################################################################################################
31 { }
32 
33 // ####################################################################################################
34 void QRcode::onParamChange(qrcode::symbol const & JEVOIS_UNUSED_PARAM(param), std::string const & newval)
35 {
36  // Disable scanning for no symbols:
37  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
38 
39  // Enable the requested ones:
40  std::vector<std::string> vec = jevois::split(newval, "/");
41  for (std::string const & v : vec)
42  if (v == "ALL")
43  {
44  itsScanner->set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);
45  itsScanner->set_config(zbar::ZBAR_EAN2, zbar::ZBAR_CFG_ENABLE, 1);
46  itsScanner->set_config(zbar::ZBAR_EAN5, zbar::ZBAR_CFG_ENABLE, 1);
47  itsScanner->set_config(zbar::ZBAR_EAN8, zbar::ZBAR_CFG_ENABLE, 1);
48  itsScanner->set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1);
49  itsScanner->set_config(zbar::ZBAR_UPCE, zbar::ZBAR_CFG_ENABLE, 1);
50  itsScanner->set_config(zbar::ZBAR_UPCA, zbar::ZBAR_CFG_ENABLE, 1);
51  itsScanner->set_config(zbar::ZBAR_ISBN10, zbar::ZBAR_CFG_ENABLE, 1);
52  itsScanner->set_config(zbar::ZBAR_ISBN13, zbar::ZBAR_CFG_ENABLE, 1);
53  itsScanner->set_config(zbar::ZBAR_COMPOSITE, zbar::ZBAR_CFG_ENABLE, 1);
54  itsScanner->set_config(zbar::ZBAR_I25, zbar::ZBAR_CFG_ENABLE, 1);
55  itsScanner->set_config(zbar::ZBAR_DATABAR, zbar::ZBAR_CFG_ENABLE, 1);
56  itsScanner->set_config(zbar::ZBAR_DATABAR_EXP, zbar::ZBAR_CFG_ENABLE, 1);
57  itsScanner->set_config(zbar::ZBAR_CODABAR, zbar::ZBAR_CFG_ENABLE, 1);
58  itsScanner->set_config(zbar::ZBAR_CODE39, zbar::ZBAR_CFG_ENABLE, 1);
59  itsScanner->set_config(zbar::ZBAR_PDF417, zbar::ZBAR_CFG_ENABLE, 1);
60  itsScanner->set_config(zbar::ZBAR_CODE93, zbar::ZBAR_CFG_ENABLE, 1);
61  itsScanner->set_config(zbar::ZBAR_CODE128, zbar::ZBAR_CFG_ENABLE, 1);
62  }
63  else if (v == "QRCODE") itsScanner->set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);
64  else if (v == "EAN2") itsScanner->set_config(zbar::ZBAR_EAN2, zbar::ZBAR_CFG_ENABLE, 1);
65  else if (v == "EAN5") itsScanner->set_config(zbar::ZBAR_EAN5, zbar::ZBAR_CFG_ENABLE, 1);
66  else if (v == "EAN8") itsScanner->set_config(zbar::ZBAR_EAN8, zbar::ZBAR_CFG_ENABLE, 1);
67  else if (v == "EAN13") itsScanner->set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1);
68  else if (v == "UPCE") itsScanner->set_config(zbar::ZBAR_UPCE, zbar::ZBAR_CFG_ENABLE, 1);
69  else if (v == "UPCA") itsScanner->set_config(zbar::ZBAR_UPCA, zbar::ZBAR_CFG_ENABLE, 1);
70  else if (v == "ISBN10")
71  {
72  itsScanner->set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1); // required?
73  itsScanner->set_config(zbar::ZBAR_ISBN10, zbar::ZBAR_CFG_ENABLE, 1);
74  }
75  else if (v == "ISBN13")
76  {
77  itsScanner->set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1); // required?
78  itsScanner->set_config(zbar::ZBAR_ISBN13, zbar::ZBAR_CFG_ENABLE, 1);
79  }
80  else if (v == "COMPOSITE") itsScanner->set_config(zbar::ZBAR_COMPOSITE, zbar::ZBAR_CFG_ENABLE, 1);
81  else if (v == "I25") itsScanner->set_config(zbar::ZBAR_I25, zbar::ZBAR_CFG_ENABLE, 1);
82  else if (v == "DATABAR") itsScanner->set_config(zbar::ZBAR_DATABAR, zbar::ZBAR_CFG_ENABLE, 1);
83  else if (v == "DATABAREXP") itsScanner->set_config(zbar::ZBAR_DATABAR_EXP, zbar::ZBAR_CFG_ENABLE, 1);
84  else if (v == "CODABAR") itsScanner->set_config(zbar::ZBAR_CODABAR, zbar::ZBAR_CFG_ENABLE, 1);
85  else if (v == "CODE39") itsScanner->set_config(zbar::ZBAR_CODE39, zbar::ZBAR_CFG_ENABLE, 1);
86  else if (v == "PDF417") itsScanner->set_config(zbar::ZBAR_PDF417, zbar::ZBAR_CFG_ENABLE, 1);
87  else if (v == "CODE93") itsScanner->set_config(zbar::ZBAR_CODE93, zbar::ZBAR_CFG_ENABLE, 1);
88  else if (v == "CODE128") itsScanner->set_config(zbar::ZBAR_CODE128, zbar::ZBAR_CFG_ENABLE, 1);
89  else LFATAL("Invalid symbol type [" << v <<']');
90 }
91 
92 // ####################################################################################################
93 void QRcode::process(zbar::Image & image)
94 {
95  // Update config using Component parameters:
96  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_X_DENSITY, qrcode::xdensity::get());
97  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_Y_DENSITY, qrcode::ydensity::get());
98 
99  // Scan for barcodes, they will be stored in the image:
100  int n = itsScanner->scan(image);
101  if (n == -1) LERROR("ZBar error");
102 }
103 
104 // ####################################################################################################
105 void QRcode::process(zbar::Image & image, std::vector<std::string> & results)
106 {
107  // Update config using Component parameters:
108  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_X_DENSITY, qrcode::xdensity::get());
109  itsScanner->set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_Y_DENSITY, qrcode::ydensity::get());
110 
111  // Clear any input junk:
112  results.clear();
113 
114  // Scan for barcodes, they will be stored in the image:
115  int n = itsScanner->scan(image);
116 
117  if (n == -1)
118  LERROR("ZBar error");
119  else if (n > 0)
120  for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol)
121  results.push_back(std::string(symbol->get_type_name()) + ' ' + symbol->get_data());
122 }
123 
std::vector< std::string > split(std::string const &input, std::string const &regex="\\s+")
void process(zbar::Image &image)
Process a greayscale image.
Definition: QRcode.C:93
#define LERROR(msg)
~QRcode()
Destructor.
Definition: QRcode.C:30
QRcode(std::string const &instance)
Constructor.
Definition: QRcode.C:23
std::shared_ptr< zbar::ImageScanner > itsScanner
Definition: QRcode.H:69
#define LFATAL(msg)
void onParamChange(qrcode::symbol const &param, std::string const &newval)
Parse symbol config strings when they change.
Definition: QRcode.C:34