CVB++ 15.0
finder.hpp
1#pragma once
2
3#include "../_cexports/c_dnc_find.h"
4#include "../string.hpp"
5#include "../dense_point_cloud.hpp"
6#include "dnc.hpp"
7#include "search_parameters.hpp"
8#include "search_result.hpp"
9#include "teach_parameters.hpp"
10
11namespace Cvb
12{
13
14 CVB_BEGIN_INLINE_NS
15
16 template <>
17 inline HandleGuard<Dnc::Finder>::HandleGuard(void *handle) noexcept
18 : HandleGuard<Dnc::Finder>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
19 {
20 }
21
22 namespace Dnc
23 {
24
26
28 class Finder final
29 {
30 private:
31 struct PrivateTag
32 {
33 };
34
35 public:
36 Finder(HandleGuard<Finder> &&guard, PrivateTag) noexcept
37 : handle_(std::move(guard))
38 {
39 }
40
42
47 static std::unique_ptr<Finder> Load(const String &fileName)
48 {
49 return Internal::DoResCallObjectOut<Finder>(
50 [&](void *&handle) { return CVB_CALL_CAPI(CVDNCCreateFromFileTyped(fileName.c_str(), handle)); });
51 }
52
54
61 static std::unique_ptr<Finder> FromHandle(HandleGuard<Finder> &&guard)
62 {
63 if (!guard.Handle())
64 throw std::runtime_error("handle must not be null");
65
66 return std::make_unique<Finder>(std::move(guard), PrivateTag{});
67 }
68
70
76 void *Handle() const noexcept
77 {
78 return handle_.Handle();
79 }
80
82
96 std::vector<SearchResult> Find(const DensePointCloud &pointCloud, const SearchParameters &parameters)
97 {
98 CVB_CALL_CAPI_CHECKED(
99 CVDNCSetSearchParams(Handle(), *reinterpret_cast<const CExports::CVDNCSearchParams *>(&parameters)));
100
101 CExports::CVDNCRESULTS resultsHandle = nullptr;
102 CVB_CALL_CAPI_CHECKED(CVDNCFind(Handle(), pointCloud.Handle(), resultsHandle));
103 ReleaseObjectGuard guard(resultsHandle);
104
105 auto numResults = CExports::CVDNCGetNumResults(resultsHandle);
106 std::vector<SearchResult> results(numResults);
107
108 for (auto &result : results)
109 {
110 int index = static_cast<int>(std::distance(&results.front(), &result));
111 CVB_CALL_CAPI_CHECKED(
112 CVDNCGetResult(resultsHandle, index, *reinterpret_cast<CExports::CVDNCResult *>(&result)));
113 }
114
115 return results;
116 }
117
119
123 void Save(const String &fileName)
124 {
125 CVB_CALL_CAPI_CHECKED(CVDNCSaveClassifierTyped(Handle(), fileName.c_str()));
126 }
127
129
139 {
140 double resolution = 0.0;
141 double fringe = 0.0;
142 TeachParameters teachParams;
143 Internal::DoResCall([this, &teachParams, &resolution, &fringe]() {
144 return CVB_CALL_CAPI(CVDNCGetTeachParams(Handle(), resolution, fringe,
145 *reinterpret_cast<CExports::CVDNCTeachParams *>(&teachParams)));
146 });
147 return std::make_tuple(teachParams, resolution, fringe);
148 }
149
150 private:
151 HandleGuard<Finder> handle_;
152 };
153
154 } // namespace Dnc
155
156 CVB_END_INLINE_NS
157
158} // namespace Cvb
A dense Cartesian 3D point cloud object.
Definition decl_dense_point_cloud.hpp:30
std::vector< SearchResult > Find(const DensePointCloud &pointCloud, const SearchParameters &parameters)
Search for objects on the given point cloud.
Definition finder.hpp:96
void Save(const String &fileName)
Saves the finder to the given file name.
Definition finder.hpp:123
std::tuple< TeachParameters, double, double > GetTeachParameters()
Gets the TeachParameters with which this Finder was trained.
Definition finder.hpp:138
static std::unique_ptr< Finder > FromHandle(HandleGuard< Finder > &&guard)
Creates a finder from a classic API handle.
Definition finder.hpp:61
void * Handle() const noexcept
Classic API node handle.
Definition finder.hpp:76
static std::unique_ptr< Finder > Load(const String &fileName)
Loads a finder from the given file name.
Definition finder.hpp:47
Definition of search parameters.
Definition search_parameters.hpp:23
Parameters for teaching a Match3D DNC finder.
Definition teach_parameters.hpp:18
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition decl_point_cloud.hpp:773
T distance(T... args)
cvbbool_t ReleaseObject(OBJ &Object)
T make_tuple(T... args)
T move(T... args)
Namespace for Match3D DNC (CAD-based 3D-object recognition).
Definition dnc.hpp:27
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49