Visual Servoing Platform  version 3.0.0
vpDetectorDataMatrixCode.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 <assert.h>
39 
40 #include <visp3/core/vpConfig.h>
41 
42 #ifdef VISP_HAVE_DMTX
43 
44 #include <dmtx.h>
45 
46 #include <visp3/detection/vpDetectorDataMatrixCode.h>
47 
52 {
53 }
54 
61 {
62  bool detected = false;
63  m_message.clear();
64  m_polygon.clear();
65  m_nb_objects = 0;
66  DmtxRegion *reg;
67  DmtxDecode *dec;
68  DmtxImage *img;
69  DmtxMessage *msg;
70 
71  img = dmtxImageCreate(I.bitmap, (int) I.getWidth(), (int) I.getHeight(), DmtxPack8bppK);
72  assert(img != NULL);
73 
74  dec = dmtxDecodeCreate(img, 1);
75  assert(dec != NULL);
76 
77  bool end = false;
78  do {
79  reg = dmtxRegionFindNext(dec, 0);
80 
81  if(reg != NULL) {
82  msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
83  if(msg != NULL) {
84 
85  std::vector<vpImagePoint> polygon;
86 
87  DmtxVector2 p00, p10, p11, p01;
88 
89  p00.X = p00.Y = p10.Y = p01.X = 0.0;
90  p10.X = p01.Y = p11.X = p11.Y = 1.0;
91  dmtxMatrix3VMultiplyBy(&p00, reg->fit2raw);
92  dmtxMatrix3VMultiplyBy(&p10, reg->fit2raw);
93  dmtxMatrix3VMultiplyBy(&p11, reg->fit2raw);
94  dmtxMatrix3VMultiplyBy(&p01, reg->fit2raw);
95 
96  polygon.push_back(vpImagePoint(I.getHeight()-p00.Y, p00.X));
97  polygon.push_back(vpImagePoint(I.getHeight()-p10.Y, p10.X));
98  polygon.push_back(vpImagePoint(I.getHeight()-p11.Y, p11.X));
99  polygon.push_back(vpImagePoint(I.getHeight()-p01.Y, p01.X));
100 
101  m_polygon.push_back(polygon);
102  detected = true;
103  m_message.push_back( (const char *)msg->output);
104 
105  m_nb_objects ++;
106  }
107  else {
108  end = true;
109  }
110  dmtxMessageDestroy(&msg);
111  }
112  else {
113  end = true;
114  }
115  dmtxRegionDestroy(&reg);
116 
117  } while (!end);
118 
119  dmtxDecodeDestroy(&dec);
120  dmtxImageDestroy(&img);
121  return detected;
122 }
123 
124 #elif !defined(VISP_BUILD_SHARED_LIBS)
125 // Work arround to avoid warning: libvisp_core.a(vpDetectorDataMatrixCode.cpp.o) has no symbols
126 void dummy_vpDetectorDataMatrixCode() {};
127 #endif
unsigned int getWidth() const
Definition: vpImage.h:161
Type * bitmap
points toward the bitmap
Definition: vpImage.h:116
size_t m_nb_objects
Number of detected objects.
std::vector< std::string > m_message
Message attached to each object.
bool detect(const vpImage< unsigned char > &I)
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:88
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.