CVB++ 15.1
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 auto originalTimeSpan = TimeLimitDecode();
223 SetTimeLimitDecode(timeSpan);
224
225 auto pResult = Internal::DoResCallObjectOut<ResultHandle>([&](void *&handle) {
226 return CVB_CALL_CAPI(CVCRDecodeMultiImageParallelizableRect(Handle(), plane.Handle(), 0, aoi.Left(),
227 aoi.Top(), aoi.Right(), aoi.Bottom(), 0, handle));
228 });
229
230 SetTimeLimitDecode(originalTimeSpan);
231 return std::make_tuple(pResult->CreateResultVector(), pResult->IsTimeLimitReached());
232 }
233
235
254 template <class Rep, class Period>
256 {
257 const auto size = plane.Parent().Size();
258 const auto aoi = Rect<int>(0, 0, size.Width() - 1, size.Height() - 1);
259
260 return ExecuteFor(plane, aoi, timeSpan);
261 }
262
264
284 template <Symbology SYM>
285 typename Config::Mapper<SYM>::Type &Config()
286 {
287 return std::get<typename Config::Mapper<SYM>::Type>(config_);
288 }
289
291
296 void SetBasicInkjetDPMEnabled(bool value);
297
299
302 bool IsBasicInkjetDPMEnabled() const;
303
305
310
312
316
318
325 void SetDetectorDensity(int value);
326
328
332 int DetectorDensity() const;
333
335
350 void SetCodeSearchSpeed(int value);
351
353
357 int CodeSearchSpeed() const;
358
359 private:
360 Decoder(Decoder &&other) noexcept
361 : handle_(std::move(other.handle_))
362 , config_(std::move(other.config_))
363 {
364 }
365
366 template <class Rep, class Period>
367 void SetTimeLimitDecode(const std::chrono::duration<Rep, Period> &timeSpan)
368 {
369 if (timeSpan.count() < 0 || timeSpan > std::chrono::milliseconds(60000))
370 throw std::invalid_argument("value for TimeLimitDecode must be <= 60000 ms");
371
372 CVB_CALL_CAPI_CHECKED(CVCRSetPropertyInt(
373 Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_TimeLimitDecode),
374 static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(timeSpan).count())));
375 }
376
377 std::chrono::milliseconds TimeLimitDecode() const;
378
379 public:
380 Decoder(const Decoder &other) = delete;
381 Decoder &operator=(const Decoder &other) = delete;
382 explicit Decoder(HandleGuard<Decoder> &&guard, PrivateTag) noexcept
383 : handle_(std::move(guard))
384 , config_(std::make_tuple(Config::DataMatrix(*this), Config::QR(*this), Config::MicroQR(*this),
385 Config::Pdf417(*this), Config::MicroPdf417(*this), Config::GS1DataBar14(*this),
386 Config::GS1DataBarStacked(*this), Config::GS1DataBarLimited(*this),
387 Config::GS1DataBarExpanded(*this), Config::GS1DataBarExpandedStacked(*this),
388 Config::Ean8(*this), Config::Ean13(*this), Config::UpcA(*this), Config::UpcE(*this),
389 Config::Code128(*this), Config::Code39(*this), Config::Code93(*this),
390 Config::Interleaved2of5(*this), Config::UspsIntelligentMail(*this),
391 Config::DutchPost(*this), Config::AustraliaPost(*this), Config::RoyalMail(*this),
392 Config::Pharmacode(*this), Config::Code32(*this), Config::Code11(*this)))
393 {
394 }
395 virtual ~Decoder() = default;
396
397 static std::unique_ptr<Decoder> FromHandle(HandleGuard<Decoder> &&guard);
398
399 void *Handle() const noexcept
400 {
401 return handle_.Handle();
402 }
403
404 private:
405 HandleGuard<Decoder> handle_;
406 std::tuple<Config::DataMatrix, Config::QR, Config::MicroQR, Config::Pdf417, Config::MicroPdf417,
407 Config::GS1DataBar14, Config::GS1DataBarStacked, Config::GS1DataBarLimited, Config::GS1DataBarExpanded,
408 Config::GS1DataBarExpandedStacked, Config::Ean8, Config::Ean13, Config::UpcA, Config::UpcE,
409 Config::Code128, Config::Code39, Config::Code93, Config::Interleaved2of5, Config::UspsIntelligentMail,
410 Config::DutchPost, Config::AustraliaPost, Config::RoyalMail, Config::Pharmacode, Config::Code32,
411 Config::Code11>
412 config_;
413 };
414 } // namespace CodeReader
415
416 CVB_END_INLINE_NS
417} // 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:255
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:285
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:31
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