ViSP  2.10.0
vpDetectorQRCode.cpp
1 /****************************************************************************
2  *
3  * $Id$
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Base class for bar code detection.
35  *
36  * Authors:
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
41 #include <visp/vpConfig.h>
42 
43 #ifdef VISP_HAVE_ZBAR
44 
45 #include <visp/vpDetectorQRCode.h>
46 
47 
52 {
53  // configure the reader
54  m_scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
55 }
56 
63 {
64  bool detected = false;
65  m_message.clear();
66  m_polygon.clear();
67  m_nb_objects = 0;
68 
69  m_scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
70  unsigned int width = I.getWidth();
71  unsigned int height = I.getHeight();
72 
73  // wrap image data
74  zbar::Image img(width, height, "Y800", I.bitmap, (unsigned long)(width * height));
75 
76  // scan the image for barcodes
77  m_nb_objects = (size_t) m_scanner.scan(img);
78 
79  // extract results
80  for(zbar::Image::SymbolIterator symbol = img.symbol_begin();
81  symbol != img.symbol_end();
82  ++symbol) {
83  m_message.push_back( symbol->get_data() );
84  detected = true;
85 
86  std::vector<vpImagePoint> polygon;
87  for(unsigned int i=0; i < (unsigned int)symbol->get_location_size(); i++){
88  polygon.push_back(vpImagePoint(symbol->get_location_y(i), symbol->get_location_x(i)));
89  }
90  m_polygon.push_back(polygon);
91  }
92 
93  // clean up
94  img.set_data(NULL, 0);
95 
96  return detected;
97 }
98 
99 #endif
unsigned int getWidth() const
Definition: vpImage.h:161
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
bool detect(const vpImage< unsigned char > &I)
size_t m_nb_objects
Number of detected objects.
std::vector< std::string > m_message
Message attached to each object.
zbar::ImageScanner m_scanner
QR code detector.
unsigned int getHeight() const
Definition: vpImage.h:152
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.