CVB++ 15.0
Loading...
Searching...
No Matches
decl_decoder.hpp
1#pragma once
2
3#include <tuple>
4
5#include "../../shims/stdoptional.hpp"
6
7#include "../../global.hpp"
8#include "../../image.hpp"
9#include "../../rect.hpp"
10
11#include "../../_cexports/c_code_reader.h"
12#include "decl_config.hpp"
13#include "../result.hpp"
14
15namespace Cvb
16{
17 CVB_BEGIN_INLINE_NS
18
19 template <>
20 inline HandleGuard<CodeReader::Decoder>::HandleGuard(void *handle) noexcept
21 : HandleGuard<CodeReader::Decoder>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
22 {
23 }
24
25 namespace CodeReader
26 {
27 class ResultHandle;
28
37
41
43
47 {
49 None = CExports::CVCRCustomPerformance::CVCRCP_None,
50
52
59 Robust = CExports::CVCRCustomPerformance::CVCRCP_Robust,
60
62
67 ExtendedRange2D = CExports::CVCRCustomPerformance::CVCRCP_ExtendedRange2D
68 };
69
71
115 class Decoder final
116 {
117 template <class T>
118 friend class ConfigBase;
119
120 private:
121 enum class Properties
122 {
123 BasicInkjet = CExports::CVCRPerformanceProperties::CVCRPP_BasicInkjet,
124 CodeSearchSpeed = CExports::CVCRPerformanceProperties::CVCRPP_CodeSearchSpeed,
125 TimeLimitDecode = CExports::CVCRPerformanceProperties::CVCRPP_TimeLimitDecode
126 };
127
128 enum class ResultProperties
129 {
130 Corners = CExports::CVCRResultProperties::CVCRRP_Corners,
131 Center = CExports::CVCRResultProperties::CVCRRP_Center,
132 SymbolType = CExports::CVCRResultProperties::CVCRRP_SymbolType,
133 SymbolTypeEx = CExports::CVCRResultProperties::CVCRRP_SymbolTypeEx,
134 Length = CExports::CVCRResultProperties::CVCRRP_Length,
135 String = CExports::CVCRResultProperties::CVCRRP_String,
136 Quality = CExports::CVCRResultProperties::CVCRRP_Quality,
137 Status = CExports::CVCRResultProperties::CVCRRP_Status,
138
139 // Result properties 2D codes
140 ECCError = CExports::CVCRResultProperties2D::CVCRRP2D_ECCError,
141 ECCErasure = CExports::CVCRResultProperties2D::CVCRRP2D_ECCErasure,
142 SymbolHeightWidth = CExports::CVCRResultProperties2D::CVCRRP2D_SymbolHeightWidth,
143 SymbolRowsColumns = CExports::CVCRResultProperties2D::CVCRRP2D_SymbolRowsColumns
144 };
145
146 struct PrivateTag
147 {
148 };
149
150 public:
152
156
165 std::vector<Result> ExecuteSingleInstance(const ImagePlane &plane, const Rect<int> &aoi);
166
181 std::vector<Result> ExecuteSingleInstance(const ImagePlane &plane);
182
184
191 std::vector<Result> Execute(const ImagePlane &plane, const Rect<int> &aoi);
192
194
201
203
218 template <class Rep, class Period>
221 {
222 SetTimeLimitDecode(timeSpan);
223
224 auto pResult = Internal::DoResCallObjectOut<ResultHandle>([&](void *&handle) {
225 return CVB_CALL_CAPI(CVCRDecodeMultiImageParallelizableRect(Handle(), plane.Handle(), 0, aoi.Left(),
226 aoi.Top(), aoi.Right(), aoi.Bottom(), 0, handle));
227 });
228
229 return std::make_tuple(pResult->CreateResultVector(), pResult->IsTimeLimitReached());
230 }
231
233
252 template <class Rep, class Period>
254 {
255 const auto size = plane.Parent().Size();
256 const auto aoi = Rect<int>(0, 0, size.Width() - 1, size.Height() - 1);
257
258 return ExecuteFor(plane, aoi, timeSpan);
259 }
260
262
282 template <Symbology SYM>
283 typename Config::Mapper<SYM>::Type &Config()
284 {
285 return std::get<typename Config::Mapper<SYM>::Type>(config_);
286 }
287
289
294 void SetBasicInkjetDPMEnabled(bool value);
295
297
300 bool IsBasicInkjetDPMEnabled() const;
301
303
308
310
314
316
323 void SetDetectorDensity(int value);
324
326
330 int DetectorDensity() const;
331
333
348 void SetCodeSearchSpeed(int value);
349
351
355 int CodeSearchSpeed() const;
356
357 private:
358 Decoder(Decoder &&other) noexcept
359 : handle_(std::move(other.handle_))
360 , config_(std::move(other.config_))
361 {
362 }
363
364 template <class Rep, class Period>
365 void SetTimeLimitDecode(const std::chrono::duration<Rep, Period> &timeSpan)
366 {
367 if (timeSpan.count() < 0 || timeSpan > std::chrono::milliseconds(60000))
368 throw std::invalid_argument("value for TimeLimitDecode must be <= 60000 ms");
369
370 CVB_CALL_CAPI_CHECKED(CVCRSetPropertyInt(
371 Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_TimeLimitDecode),
372 static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(timeSpan).count())));
373 }
374
375 public:
376 Decoder(const Decoder &other) = delete;
377 Decoder &operator=(const Decoder &other) = delete;
378 explicit Decoder(HandleGuard<Decoder> &&guard, PrivateTag) noexcept
379 : handle_(std::move(guard))
380 , config_(std::make_tuple(Config::DataMatrix(*this), Config::QR(*this), Config::MicroQR(*this),
381 Config::Pdf417(*this), Config::MicroPdf417(*this), Config::GS1DataBar14(*this),
382 Config::GS1DataBarStacked(*this), Config::GS1DataBarLimited(*this),
383 Config::GS1DataBarExpanded(*this), Config::GS1DataBarExpandedStacked(*this),
384 Config::Ean8(*this), Config::Ean13(*this), Config::UpcA(*this), Config::UpcE(*this),
385 Config::Code128(*this), Config::Code39(*this), Config::Code93(*this),
386 Config::Interleaved2of5(*this), Config::UspsIntelligentMail(*this),
387 Config::DutchPost(*this), Config::AustraliaPost(*this), Config::RoyalMail(*this),
388 Config::Pharmacode(*this), Config::Code32(*this), Config::Code11(*this)))
389 {
390 }
391 virtual ~Decoder() = default;
392
393 static std::unique_ptr<Decoder> FromHandle(HandleGuard<Decoder> &&guard);
394
395 void *Handle() const noexcept
396 {
397 return handle_.Handle();
398 }
399
400 private:
401 HandleGuard<Decoder> handle_;
402 std::tuple<Config::DataMatrix, Config::QR, Config::MicroQR, Config::Pdf417, Config::MicroPdf417,
403 Config::GS1DataBar14, Config::GS1DataBarStacked, Config::GS1DataBarLimited, Config::GS1DataBarExpanded,
404 Config::GS1DataBarExpandedStacked, Config::Ean8, Config::Ean13, Config::UpcA, Config::UpcE,
405 Config::Code128, Config::Code39, Config::Code93, Config::Interleaved2of5, Config::UspsIntelligentMail,
406 Config::DutchPost, Config::AustraliaPost, Config::RoyalMail, Config::Pharmacode, Config::Code32,
407 Config::Code11>
408 config_;
409 };
410 } // namespace CodeReader
411
412 CVB_END_INLINE_NS
413} // namespace Cvb
Class for decoding.
Definition decl_decoder.hpp:116
void SetCodeSearchSpeed(int value)
Sets the code search speed.
Definition detail_decoder.hpp:73
void SetDetectorDensity(int value)
Sets the detector density to control the search aggressiveness for small codes.
Definition detail_decoder.hpp:55
CodeReader::CustomPerformance CustomPerformance() const
Retrieves the custom image processing method used to optimize decoding robustness and performance.
Definition detail_decoder.hpp:47
TimeLimitedDecoderResult ExecuteFor(const ImagePlane &plane, const Rect< int > &aoi, const std::chrono::duration< Rep, Period > &timeSpan)
Performs the decoding within a specified time limit.
Definition decl_decoder.hpp:219
bool IsBasicInkjetDPMEnabled() const
Checks whether the Basic Inkjet DPM mode is enabled.
Definition detail_decoder.hpp:33
int CodeSearchSpeed() const
Retrieves the code search speed.
Definition detail_decoder.hpp:83
TimeLimitedDecoderResult ExecuteFor(const ImagePlane &plane, const std::chrono::duration< Rep, Period > &timeSpan)
Performs the decoding within a specified time limit.
Definition decl_decoder.hpp:253
int DetectorDensity() const
Retrieves the detector density to control the search aggressiveness for small codes.
Definition detail_decoder.hpp:65
Config::Mapper< SYM >::Type & Config()
Retrieves the configuration object for a specific symbology.
Definition decl_decoder.hpp:283
std::vector< Result > Execute(const ImagePlane &plane, const Rect< int > &aoi)
Performs the decoding.
Definition detail_decoder.hpp:109
static std::unique_ptr< Decoder > Create()
Creates and returns a new Decoder instance.
Definition detail_decoder.hpp:21
void SetCustomPerformance(CustomPerformance value)
Sets the custom image processing method used to optimize decoding robustness and performance.
Definition detail_decoder.hpp:40
void SetBasicInkjetDPMEnabled(bool value)
Enables or disables the reading of Basic Inkjet DPM (Direct Part Marking) codes.
Definition detail_decoder.hpp:27
Size2D< int > Size() const noexcept
Size of the image in pixels.
Definition decl_image.hpp:428
Image plane information container.
Definition decl_image_plane.hpp:29
void * Handle() const noexcept override
Classic API image handle.
Definition detail_image_plane.hpp:35
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
Rectangle object.
Definition rect.hpp:24
T Bottom() const noexcept
Gets bottom row of the rectangle (still inside the rectangle).
Definition rect.hpp:144
T Top() const noexcept
Gets first row of the rectangle.
Definition rect.hpp:104
T Right() const noexcept
Gets rightmost column of the rectangle (still inside the rectangle).
Definition rect.hpp:124
T Left() const noexcept
Gets first column of the rectangle.
Definition rect.hpp:84
T duration_cast(T... args)
cvbbool_t ReleaseObject(OBJ &Object)
T make_tuple(T... args)
T move(T... args)
Namespace for all decoding functionalities.
Definition decl_config_2d_codes.hpp:10
CustomPerformance
Enum class specifying custom image processing methods to improve decoding robustness and performance.
Definition decl_decoder.hpp:47
@ ExtendedRange2D
Extends the readable range for 2D codes in the central area of the image.
Definition decl_decoder.hpp:67
@ None
No additional processing is applied.
Definition decl_decoder.hpp:49
@ Robust
Enables robust decoding for a single code.
Definition decl_decoder.hpp:59
TimeLimitStatus
Enum class specifying decoder status returned by function Cvb::CodeReader::Decoder::ExecuteFor.
Definition decl_decoder.hpp:31
@ TimeLimitReached
Specified time limit for decoding reached. Decoding aborted.
Definition decl_decoder.hpp:35
@ InTime
Decoding sucessfully finished.
Definition decl_decoder.hpp:33
std::tuple< std::vector< Result >, TimeLimitStatus > TimeLimitedDecoderResult
Definition decl_decoder.hpp:40
Root namespace for the Image Manager interface.
Definition version.hpp:11