Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDetectorQRCode.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Base class for bar code detection.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #ifdef VISP_HAVE_ZBAR
41 
42 #include <visp3/detection/vpDetectorQRCode.h>
43 
44 
49 {
50  // configure the reader
51  m_scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
52 }
53 
60 {
61  bool detected = false;
62  m_message.clear();
63  m_polygon.clear();
64  m_nb_objects = 0;
65 
66  m_scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
67  unsigned int width = I.getWidth();
68  unsigned int height = I.getHeight();
69 
70  // wrap image data
71  zbar::Image img(width, height, "Y800", I.bitmap, (unsigned long)(width * height));
72 
73  // scan the image for barcodes
74  m_nb_objects = (size_t) m_scanner.scan(img);
75 
76  // extract results
77  for(zbar::Image::SymbolIterator symbol = img.symbol_begin();
78  symbol != img.symbol_end();
79  ++symbol) {
80  m_message.push_back( symbol->get_data() );
81  detected = true;
82 
83  std::vector<vpImagePoint> polygon;
84  for(unsigned int i=0; i < (unsigned int)symbol->get_location_size(); i++){
85  polygon.push_back(vpImagePoint(symbol->get_location_y(i), symbol->get_location_x(i)));
86  }
87  m_polygon.push_back(polygon);
88  }
89 
90  // clean up
91  img.set_data(NULL, 0);
92 
93  return detected;
94 }
95 #elif !defined(VISP_BUILD_SHARED_LIBS)
96 // Work arround to avoid warning: libvisp_core.a(vpDetectorQRCode.cpp.o) has no symbols
97 void dummy_vpDetectorQRCode() {};
98 #endif
unsigned int getWidth() const
Definition: vpImage.h:226
Type * bitmap
points toward the bitmap
Definition: vpImage.h:134
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:175
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.