Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDetectorDataMatrixCode.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
34#include <assert.h>
35
36#include <visp3/core/vpConfig.h>
37
38#ifdef VISP_HAVE_DMTX
39
40#include <dmtx.h>
41
42#include <visp3/detection/vpDetectorDataMatrixCode.h>
43
50
59{
60 bool detected = false;
61 m_message.clear();
62 m_polygon.clear();
63 m_nb_objects = 0;
64 DmtxRegion *reg;
65 DmtxDecode *dec;
66 DmtxImage *img;
67 DmtxMessage *msg;
68
69 DmtxTime *dmtx_timeout = nullptr;
70 if (m_timeout_ms) {
71 dmtx_timeout = new DmtxTime;
72 *dmtx_timeout = dmtxTimeNow();
73 dmtx_timeout->usec += m_timeout_ms * 1000;
74 }
75
76 img = dmtxImageCreate(I.bitmap, static_cast<int>(I.getWidth()), static_cast<int>(I.getHeight()), DmtxPack8bppK);
77 assert(img != nullptr);
78
79 dec = dmtxDecodeCreate(img, 1);
80 assert(dec != nullptr);
81
82 bool end = false;
83 do {
84 reg = dmtxRegionFindNext(dec, dmtx_timeout);
85
86 if (reg != nullptr) {
87 msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
88 if (msg != nullptr) {
89
90 std::vector<vpImagePoint> polygon;
91
92 DmtxVector2 p00, p10, p11, p01;
93
94 p00.X = p00.Y = p10.Y = p01.X = 0.0;
95 p10.X = p01.Y = p11.X = p11.Y = 1.0;
96 dmtxMatrix3VMultiplyBy(&p00, reg->fit2raw);
97 dmtxMatrix3VMultiplyBy(&p10, reg->fit2raw);
98 dmtxMatrix3VMultiplyBy(&p11, reg->fit2raw);
99 dmtxMatrix3VMultiplyBy(&p01, reg->fit2raw);
100
101 polygon.push_back(vpImagePoint(I.getHeight() - p00.Y, p00.X));
102 polygon.push_back(vpImagePoint(I.getHeight() - p10.Y, p10.X));
103 polygon.push_back(vpImagePoint(I.getHeight() - p11.Y, p11.X));
104 polygon.push_back(vpImagePoint(I.getHeight() - p01.Y, p01.X));
105
106 m_polygon.push_back(polygon);
107 detected = true;
108 m_message.push_back((const char *)msg->output);
109
110 m_nb_objects++;
111 }
112 else {
113 end = true;
114 }
115 dmtxMessageDestroy(&msg);
116 }
117 else {
118 end = true;
119 }
120 dmtxRegionDestroy(&reg);
121
122 } while (!end);
123
124 dmtxDecodeDestroy(&dec);
125 dmtxImageDestroy(&img);
126 if (dmtx_timeout) {
127 delete dmtx_timeout;
128 }
129 return detected;
130}
131END_VISP_NAMESPACE
132#elif !defined(VISP_BUILD_SHARED_LIBS)
133// Work around to avoid warning:
134// libvisp_core.a(vpDetectorDataMatrixCode.cpp.o) has no symbols
135void dummy_vpDetectorDataMatrixCode() { }
136#endif
std::vector< std::string > m_message
Message attached to each object.
std::vector< std::vector< vpImagePoint > > m_polygon
For each object, defines the polygon that contains the object.
void setTimeout(unsigned long timeout_ms)
size_t m_nb_objects
Number of detected objects.
unsigned long m_timeout_ms
Detection timeout.
bool detect(const vpImage< unsigned char > &I) VP_OVERRIDE
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:131