CVB++ 15.0
detail_result_handle.hpp
1#pragma once
2
3#include "../_decl/decl_result_handle.hpp"
4#include "../_decl/decl_symbology_conversion.hpp"
5#include "../../point_2d.hpp"
6#include "../../size_2d.hpp"
7
8namespace Cvb
9{
10 CVB_BEGIN_INLINE_NS
11
12 namespace CodeReader
13 {
14 inline Cvb::optional<Result2D> ResultHandle::TryCreateResult2D(size_t i) const
15 {
16 // try to get 2D properties
17 double width = 0;
18 if (CVB_CALL_CAPI(
19 CVCRGetDecoderResultDouble(Handle(), i, CExports::CVCRResultPropertyDouble::CVCRRPF_Width, width))
20 == 0)
21 {
22 // size
23 const auto height = Internal::DoResCallValueOut<double>([&](double &value) {
24 return CVB_CALL_CAPI(
25 CVCRGetDecoderResultDouble(Handle(), i, CExports::CVCRResultPropertyDouble::CVCRRPF_Height, value));
26 });
27
28 // rows
29 const auto rows = Internal::DoResCallValueOut<int>([&](int &value) {
30 return CVB_CALL_CAPI(
31 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_Rows, value));
32 });
33
34 // columns
35 const auto cols = Internal::DoResCallValueOut<int>([&](int &value) {
36 return CVB_CALL_CAPI(
37 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_Columns, value));
38 });
39
40 // quality
41 const auto quality = Internal::DoResCallValueOut<int>([&](int &value) {
42 return CVB_CALL_CAPI(
43 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_Quality, value));
44 });
45
46 // error correction codewords
47 const auto errorCorrectionCodewords = Internal::DoResCallValueOut<int>([&](int &value) {
48 return CVB_CALL_CAPI(CVCRGetDecoderResultInt(
49 Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_ErrorCorrectionCodewords, value));
50 });
51
52 // error correction erasure codewords
53 const auto errorCorrectionErasureCodewords = Internal::DoResCallValueOut<int>([&](int &value) {
54 return CVB_CALL_CAPI(CVCRGetDecoderResultInt(
55 Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_ErrorCorrectionErasureCodewords, value));
56 });
57
58 // composite type
59 const auto compositeType =
60 static_cast<CodeReader::CompositeType>(Internal::DoResCallValueOut<int>([&](int &value) {
61 return CVB_CALL_CAPI(
62 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_CompositeType, value));
63 }));
64
65 return Result2D(quality, rows, cols, Cvb::Size2D<double>(width, height), errorCorrectionCodewords,
66 errorCorrectionErasureCodewords, compositeType);
67 }
68
69 return {};
70 }
71
72 inline std::vector<Result> ResultHandle::CreateResultVector() const
73 {
74 // number of detected codes
75 const auto numSymbolsDetected = Internal::DoResCallValueOut<size_t>(
76 [&](size_t &value) { return CVB_CALL_CAPI(CVCRGetDecoderResultCount(Handle(), value)); });
77 auto results = std::vector<Result>(numSymbolsDetected);
78
79 for (size_t i = 0; i < numSymbolsDetected; i++)
80 {
81 // General code parameters (1D and 2D)
82
83 // decoded data
84 size_t size = 0;
85 CVB_CALL_CAPI_CHECKED(CVCRGetDecoderResultDataTyped(Handle(), i, reinterpret_cast<Char *>(NULL), size));
86 String data(size - 1, '\0');
87 CVB_CALL_CAPI_CHECKED(CVCRGetDecoderResultDataTyped(Handle(), i, &data[0], size));
88
89 // symbology
90 Symbology symbology = Symbology::Unknown;
91 const auto symbolInt = Internal::DoResCallValueOut<int>([&](int &value) {
92 return CVB_CALL_CAPI(
93 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_Symbology, value));
94 });
95 const auto isExtendedSymbology = Internal::DoResCallValueOut<int>([&](int &value) {
96 return CVB_CALL_CAPI(CVCRGetDecoderResultInt(
97 Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_IsExtendedSymbology, value));
98 });
99 if (isExtendedSymbology == 1) // extended symbology
100 {
101 symbology = SymbologyConversion::Convert(static_cast<CExports::CVCRValueSymbologyEx>(symbolInt));
102 }
103 else
104 {
105 symbology = SymbologyConversion::Convert(static_cast<CExports::CVCRValueSymbology>(symbolInt));
106 }
107
108 // decode status
109 const auto decodeStatus =
110 static_cast<CodeReader::DecodeStatus>(Internal::DoResCallValueOut<int>([&](int &value) {
111 return CVB_CALL_CAPI(
112 CVCRGetDecoderResultInt(Handle(), i, CExports::CVCRResultPropertyInt::CVCRRPI_DecodeStatus, value));
113 }));
114
115 // center
116 Cvb::Point2D<int> center;
117 Internal::DoResCall([&]() {
118 return CVB_CALL_CAPI(
119 CVCRGetDecoderResultCenter(Handle(), i, *reinterpret_cast<CExports::CVCRPoint *>(&center)));
120 });
121
122 // corners
123 std::array<Point2D<int>, 4> corners;
124 Internal::DoResCall([&]() {
125 return CVB_CALL_CAPI(
126 CVCRGetDecoderResultCorners(Handle(), i, reinterpret_cast<CExports::CVCRPoint *>(corners.data())));
127 });
128
129 // try to get 2D parameters
130 const auto result2D = TryCreateResult2D(i);
131 results[i] = Result(std::move(data), center, std::move(corners), symbology, decodeStatus, result2D);
132 }
133 return results;
134 }
135
136 } // namespace CodeReader
137
138 CVB_END_INLINE_NS
139} // namespace Cvb
Namespace for all decoding functionalities.
Definition decl_config_2d_codes.hpp:10
Symbology
Enum class listing all supported symbologies.
Definition decl_config_base.hpp:35
@ Unknown
Unknown symbology.
Definition decl_config_base.hpp:37
CompositeType
Enum class representing the type of composite code.
Definition result.hpp:58
DecodeStatus
Enum class for decoding status.
Definition result.hpp:46
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49