ViSP  2.10.0
vpDetectorDataMatrixCode.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 <assert.h>
42 
43 #include <visp/vpConfig.h>
44 
45 #ifdef VISP_HAVE_DMTX
46 
47 #include <dmtx.h>
48 
49 #include <visp/vpDetectorDataMatrixCode.h>
50 
55 {
56 }
57 
64 {
65  bool detected = false;
66  m_message.clear();
67  m_polygon.clear();
68  m_nb_objects = 0;
69  DmtxRegion *reg;
70  DmtxDecode *dec;
71  DmtxImage *img;
72  DmtxMessage *msg;
73 
74  img = dmtxImageCreate(I.bitmap, (int) I.getWidth(), (int) I.getHeight(), DmtxPack8bppK);
75  assert(img != NULL);
76 
77  dec = dmtxDecodeCreate(img, 1);
78  assert(dec != NULL);
79 
80  bool end = false;
81  do {
82  reg = dmtxRegionFindNext(dec, 0);
83 
84  if(reg != NULL) {
85  msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
86  if(msg != NULL) {
87 
88  std::vector<vpImagePoint> polygon;
89 
90  DmtxVector2 p00, p10, p11, p01;
91 
92  p00.X = p00.Y = p10.Y = p01.X = 0.0;
93  p10.X = p01.Y = p11.X = p11.Y = 1.0;
94  dmtxMatrix3VMultiplyBy(&p00, reg->fit2raw);
95  dmtxMatrix3VMultiplyBy(&p10, reg->fit2raw);
96  dmtxMatrix3VMultiplyBy(&p11, reg->fit2raw);
97  dmtxMatrix3VMultiplyBy(&p01, reg->fit2raw);
98 
99  polygon.push_back(vpImagePoint(I.getHeight()-p00.Y, p00.X));
100  polygon.push_back(vpImagePoint(I.getHeight()-p10.Y, p10.X));
101  polygon.push_back(vpImagePoint(I.getHeight()-p11.Y, p11.X));
102  polygon.push_back(vpImagePoint(I.getHeight()-p01.Y, p01.X));
103 
104  m_polygon.push_back(polygon);
105  detected = true;
106  m_message.push_back( (const char *)msg->output);
107 
108  m_nb_objects ++;
109  }
110  else {
111  end = true;
112  }
113  dmtxMessageDestroy(&msg);
114  }
115  else {
116  end = true;
117  }
118  dmtxRegionDestroy(&reg);
119 
120  } while (!end);
121 
122  dmtxDecodeDestroy(&dec);
123  dmtxImageDestroy(&img);
124  return detected;
125 }
126 
127 #endif
unsigned int getWidth() const
Definition: vpImage.h:161
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
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:93
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.