CVB++ 15.0
correlation.hpp
1#pragma once
2
3#if defined _WIN32
4
5# include "../_cexports/c_foundation.h"
6
7# include "../global.hpp"
8# include "../image.hpp"
9# include "../exception.hpp"
10# include "../analyze.hpp"
11# include "../rect.hpp"
12# include "../_detail/detail_pixel_list.hpp"
13
14# include <memory>
15# include <vector>
16
17namespace Cvb
18{
19 CVB_BEGIN_INLINE_NS
20
21 namespace Foundation
22 {
23
25
29 namespace Correlation
30 {
31
55
57
77 inline std::unique_ptr<Image> Correlate(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
78 Rect<int> aoi, CorrelationMethod method)
79 {
80 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
81 switch (method)
82 {
84 return CVB_CALL_CAPI(CalculateCorrelationCoefficients(
85 imagePlane.Parent().Handle(), imagePlane.Plane(), templatePlane.Parent().Handle(),
86 templatePlane.Plane(), aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(), resimg));
88 return CVB_CALL_CAPI(CalculateCrossCorrelations(
89 imagePlane.Parent().Handle(), imagePlane.Plane(), templatePlane.Parent().Handle(),
90 templatePlane.Plane(), aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(), resimg));
92 return CVB_CALL_CAPI(CalculateSumOfSquareDistances(
93 imagePlane.Parent().Handle(), imagePlane.Plane(), templatePlane.Parent().Handle(),
94 templatePlane.Plane(), aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(), resimg));
95 default:
96 throw std::invalid_argument("unknown correlation method");
97 }
98 });
99 }
100
102
121 inline std::unique_ptr<Image> Correlate(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
122 CorrelationMethod method)
123 {
124 return Correlate(imagePlane, templatePlane, imagePlane.Parent().Bounds(), method);
125 }
126
128
147 inline std::unique_ptr<Image> Correlate(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
148 Rect<int> aoi)
149 {
150 return Correlate(imagePlane, templatePlane, aoi, CorrelationMethod::CorrelationCoefficients);
151 }
152
154
172 inline std::unique_ptr<Image> Correlate(const ImagePlane &imagePlane, const ImagePlane &templatePlane)
173 {
174 return Correlate(imagePlane, templatePlane, imagePlane.Parent().Bounds());
175 }
176
179
197 inline std::vector<LocalMaximum> FindMatches(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
198 double threshold, int locality, Rect<int> aoi,
200 Neighborhood subPixRadius = Neighborhood::Use3x3)
201 {
202 auto pixelList = Internal::DoResCallObjectOut<Internal::PixelList>([&](void *&resobj) {
203 return CVB_CALL_CAPI(FindCorrelationMatches(
204 imagePlane.Parent().Handle(), imagePlane.Plane(), templatePlane.Parent().Handle(), templatePlane.Plane(),
205 aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(), threshold, locality,
206 static_cast<CExports::TSubPixelMode>(subPixMode), static_cast<CExports::cvbdim_t>(subPixRadius), resobj));
207 });
208 return pixelList->ToLocalMaximum();
209 }
210
213
230 inline std::vector<LocalMaximum> FindMatches(const ImagePlane &imagePlane, const ImagePlane &templatePlane,
231 double threshold, int locality,
233 Neighborhood subPixRadius = Neighborhood::Use3x3)
234 {
235 return FindMatches(imagePlane, templatePlane, threshold, locality, imagePlane.Parent().Bounds(), subPixMode,
236 subPixRadius);
237 }
238
239 } /* namespace Correlation */
240
242
245
246 } /* namespace Foundation */
247 CVB_END_INLINE_NS
248} /* namespace Cvb */
249
250#endif
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
Rectangle object.
Definition rect.hpp:24
cvbres_t CalculateSumOfSquareDistances(IMG ImgIn, long IndexIn, IMG Template, long IndexTemplate, long left, long top, long right, long bottom, IMG &Accumulator)
cvbres_t CalculateCrossCorrelations(IMG ImgIn, long IndexIn, IMG Template, long IndexTemplate, long left, long top, long right, long bottom, IMG &Accumulator)
cvbres_t CalculateCorrelationCoefficients(IMG ImgIn, long IndexIn, IMG Template, long IndexTemplate, long left, long top, long right, long bottom, IMG &Accumulator)
Namespace for collection of functions that calculate different kinds of correlation values.
Definition correlation.hpp:30
std::vector< LocalMaximum > FindMatches(const ImagePlane &imagePlane, const ImagePlane &templatePlane, double threshold, int locality, Rect< int > aoi, SubPixelMode subPixMode=SubPixelMode::ParabolicFast, Neighborhood subPixRadius=Neighborhood::Use3x3)
Use the correlation coefficient calculation method to find locations in the input image plane that ma...
Definition correlation.hpp:197
CorrelationMethod
Correlation calculation methods.
Definition correlation.hpp:34
@ SumOfSquareDistances
Normalized sum of square distances.
Definition correlation.hpp:43
@ CrossCorrelation
Calculate the cross correlations between image and template.
Definition correlation.hpp:53
@ CorrelationCoefficients
Calculate the normalized correlation coefficients between image and template.
Definition correlation.hpp:51
std::unique_ptr< Image > Correlate(const ImagePlane &imagePlane, const ImagePlane &templatePlane, Rect< int > aoi, CorrelationMethod method)
Calculate the correlation between a plane and a template using a selectable calculation method.
Definition correlation.hpp:77
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
SubPixelMode
Method for determining sub pixel accuracy when working with the FindLocalMaxima functions.
Definition global.hpp:312
@ ParabolicFast
Definition global.hpp:318
Neighborhood
Neighborhood to use in sub pixel calculation of local maxima.
Definition global.hpp:337
@ Use3x3
Definition global.hpp:341