CVB++ 15.0
Loading...
Searching...
No Matches
detail_decoder.hpp
1#pragma once
2
3#include "../result.hpp"
4#include "../_decl/decl_decoder.hpp"
5#include "../_decl/decl_result_handle.hpp"
6
7namespace Cvb
8{
9 CVB_BEGIN_INLINE_NS
10
11 namespace CodeReader
12 {
13 inline std::unique_ptr<Decoder> Decoder::FromHandle(HandleGuard<Decoder> &&guard)
14 {
15 if (!guard.Handle())
16 throw std::runtime_error("decoder handle must not be null");
17
18 return std::make_unique<Decoder>(std::move(guard), PrivateTag{});
19 }
20
22 {
23 return Internal::DoResCallObjectOut<Decoder>(
24 [&](void *&handle) { return CVB_CALL_CAPI(CVCRCreateDecoder(handle)); });
25 }
26
27 inline void Decoder::SetBasicInkjetDPMEnabled(bool value)
28 {
29 CVB_CALL_CAPI_CHECKED(
30 CVCRSetPropertyInt(Handle(), static_cast<int>(Properties::BasicInkjet), static_cast<int>(value)));
31 }
32
34 {
35 int value = 0;
36 CVB_CALL_CAPI_CHECKED(CVCRGetPropertyInt(Handle(), static_cast<int>(Properties::BasicInkjet), value));
37 return static_cast<bool>(value);
38 }
39
41 {
42 CVB_CALL_CAPI_CHECKED(
43 CVCRSetPropertyInt(Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_CustomPerformance),
44 static_cast<int>(value)));
45 }
46
48 {
49 int value = 0;
50 CVB_CALL_CAPI_CHECKED(CVCRGetPropertyInt(
51 Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_CustomPerformance), value));
52 return static_cast<CodeReader::CustomPerformance>(value);
53 }
54
55 inline void Decoder::SetDetectorDensity(int value)
56 {
57 if (value < 1 || value > 4)
58 throw std::invalid_argument("value for DetectorDensity must be between 1 and 4 (inclusive)");
59
60 CVB_CALL_CAPI_CHECKED(
61 CVCRSetPropertyInt(Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_DetectorDensity),
62 static_cast<int>(value)));
63 }
64
65 inline int Decoder::DetectorDensity() const
66 {
67 int value = 0;
68 CVB_CALL_CAPI_CHECKED(CVCRGetPropertyInt(
69 Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_DetectorDensity), value));
70 return value;
71 }
72
73 inline void Decoder::SetCodeSearchSpeed(int value)
74 {
75 if (value < 0 || value > 3)
76 throw std::invalid_argument("the value for CodeSearchSpeed must be one of 0,1,2 or 3");
77
78 CVB_CALL_CAPI_CHECKED(
79 CVCRSetPropertyInt(Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_CodeSearchSpeed),
80 static_cast<int>(value)));
81 }
82
83 inline int Decoder::CodeSearchSpeed() const
84 {
85 int value = 0;
86 CVB_CALL_CAPI_CHECKED(CVCRGetPropertyInt(
87 Handle(), static_cast<int>(CExports::CVCRPerformanceProperties::CVCRPP_CodeSearchSpeed), value));
88 return value;
89 }
90
91 inline std::vector<Result> Decoder::ExecuteSingleInstance(const ImagePlane &plane, const Rect<int> &aoi)
92 {
93 auto pResult = Internal::DoResCallObjectOut<ResultHandle>([&](void *&handle) {
94 return CVB_CALL_CAPI(CVCRDecodeMultiImageWithResultRect(Handle(), plane.Handle(), 0, aoi.Left(), aoi.Top(),
95 aoi.Right(), aoi.Bottom(), 0, 0, handle));
96 });
97
98 return pResult->CreateResultVector();
99 }
100
101 inline std::vector<Result> Decoder::ExecuteSingleInstance(const ImagePlane &plane)
102 {
103 const auto size = plane.Parent().Size();
104 const auto aoi = Rect<int>(0, 0, size.Width() - 1, size.Height() - 1);
105
106 return ExecuteSingleInstance(plane, aoi);
107 }
108
110 {
111 auto pResult = Internal::DoResCallObjectOut<ResultHandle>([&](void *&handle) {
112 return CVB_CALL_CAPI(CVCRDecodeMultiImageParallelizableRect(Handle(), plane.Handle(), 0, aoi.Left(), aoi.Top(),
113 aoi.Right(), aoi.Bottom(), 0, handle));
114 });
115
116 return pResult->CreateResultVector();
117 }
118
120 {
121 const auto size = plane.Parent().Size();
122 const auto aoi = Rect<int>(0, 0, size.Width() - 1, size.Height() - 1);
123
124 return Execute(plane, aoi);
125 }
126 } // namespace CodeReader
127
128 CVB_END_INLINE_NS
129
130} // namespace Cvb
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
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
int DetectorDensity() const
Retrieves the detector density to control the search aggressiveness for small codes.
Definition detail_decoder.hpp:65
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
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
Root namespace for the Image Manager interface.
Definition version.hpp:11