CVB++ 15.0
minos_correlation.hpp
1#pragma once
2
3#include "../_cexports/c_minos.h"
4
5#include "search_result.hpp"
6
7#include "../global.hpp"
8#include "../image.hpp"
9#include "../string.hpp"
10#include "../area_2d.hpp"
11
12#include <vector>
13#include <cmath>
14
15namespace Cvb
16{
17 CVB_BEGIN_INLINE_NS
18
20 namespace Minos
21 {
22
23 namespace Private
24 {
25 const int CorrelationMaxSearch = 32767;
26
27 const Cvb::Char *const CorrelationResultId = CVB_LIT("[correlation]");
28
29 } /* namespace Private */
30
32
46 const ImagePlane &templatePlane, double threshold,
47 int radius, Area2D aoi, double density = 1.0)
48 {
49 CExports::RESULTS hSearchResults = nullptr;
50 CVB_CALL_CAPI_CHECKED(OptCorrelations(imagePlane.Parent().Handle(), templatePlane.Parent().Handle(),
51 imagePlane.Plane(), templatePlane.Plane(), std::lround(density * 1000.0),
52 reinterpret_cast<CExports::TArea &>(aoi), threshold, radius,
53 Private::CorrelationMaxSearch, nullptr, nullptr, hSearchResults));
54 ReleaseObjectGuard hSearchResHolder(hSearchResults);
55 auto results = Private::SearchResultsToArray(hSearchResults);
56 for (auto &&result : results)
57 {
58 result =
59 SearchResult(Private::CorrelationResultId, result.Quality(), result.Position(), result.AdvanceVector());
60 }
61 return results;
62 }
63
65
78 const ImagePlane &templatePlane, double threshold,
79 int radius, double density = 1.0)
80 {
81 return SearchAllCorrelations(imagePlane, templatePlane, threshold, radius,
82 Area2D(static_cast<Rect<double>>(imagePlane.Parent().Bounds())), density);
83 }
84
86
96 inline SearchResult SearchCorrelation(const ImagePlane &imagePlane, const ImagePlane &templatePlane, Area2D aoi,
97 double density = 1.0)
98 {
99 double correlation = 0.0, posX = std::numeric_limits<double>::quiet_NaN(),
101 CVB_CALL_CAPI_CHECKED(OptCorrelation(imagePlane.Parent().Handle(), templatePlane.Parent().Handle(),
102 imagePlane.Plane(), templatePlane.Plane(), std::lround(density * 1000.0),
103 reinterpret_cast<CExports::TArea &>(aoi), true, correlation, posX, posY));
104 if (correlation == 0.0)
105 {
106 return SearchResult();
107 }
108 else
109 {
110 return SearchResult(Private::CorrelationResultId, correlation, Point2D<double>(posX, posY),
111 Point2D<double>(0.0, 0.0));
112 }
113 }
114
116
125 inline SearchResult SearchCorrelation(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
126 double density = 1.0)
127 {
128 return SearchCorrelation(imagePlane, templatePlane,
129 Area2D(static_cast<Rect<double>>(imagePlane.Parent().Bounds())), density);
130 }
131
132 } /* namespace Minos */
133 CVB_END_INLINE_NS
134} /* namespace Cvb */
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Image plane information container.
Definition decl_image_plane.hpp:29
int Plane() const noexcept
Plane index in the image, to which this plane refers to.
Definition decl_image_plane.hpp:147
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
Search result returned by Minos.
Definition search_result.hpp:25
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Rectangle object.
Definition rect.hpp:24
Namespace for the Minos package.
Definition classifier.hpp:29
SearchResult SearchCorrelation(const ImagePlane &imagePlane, const ImagePlane &templatePlane, Area2D aoi, double density=1.0)
Find the best correlation match of the templatePlane in the imagePlane aoi with sub-pixel accuracy.
Definition minos_correlation.hpp:96
std::vector< SearchResult > SearchAllCorrelations(const ImagePlane &imagePlane, const ImagePlane &templatePlane, double threshold, int radius, Area2D aoi, double density=1.0)
Find all correlation matches of the templatePlane in the imagePlane aoi.
Definition minos_correlation.hpp:45
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
T quiet_NaN(T... args)
T lround(T... args)