CVB++ 15.0
image_extensions.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 "../area_2d.hpp"
11# include "../rect.hpp"
12
13# include "transform_2d.hpp"
14
15# include <vector>
16# include <memory>
17
18namespace Cvb
19{
20 CVB_BEGIN_INLINE_NS
21
22 namespace Foundation
23 {
24
26
31 {
32
34
42 template <class RANGE>
43 inline typename TypedRange<void, double, RANGE>::type InitAOI(Image &image, Rect<int> aoi, const RANGE &values)
44 {
45 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
46
47 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
48 CVB_CALL_CAPI_CHECKED(InitializeImageRect(image.Handle(), aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(),
49 const_cast<double *>(valuesRange.Data())));
50 }
51
53
60 inline void InitAOI(Image &image, Rect<int> aoi, double value)
61 {
62 InitAOI(image, aoi, std::vector<double>(image.PlanesCount(), value));
63 }
64
66
73 template <class RANGE>
74 inline typename TypedRange<void, double, RANGE>::type InitImage(Image &image, const RANGE &values)
75 {
76 InitAOI(image, image.Bounds(), values);
77 }
78
80
86 inline void InitImage(Image &image, double value)
87 {
88 InitAOI(image, image.Bounds(), value);
89 }
90
92
100 inline std::unique_ptr<Image> SubImage(const Image &image, Area2D aoi,
101 Interpolation interpolation = Interpolation::Linear)
102 {
103 /* Note: the C-function AreaSubImage expects the aoi TArea parameter in swapped orientation (P1<->P2) than how
104 * it's defined in Area2D... */
105 aoi.SwapOrientation();
106
107 /* Note: the binary compatibility between Area2D and TArea is guaranteed, therefore the cast below is legal. */
108 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
109 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
110 return CVB_CALL_CAPI(AreaSubImage(image.Handle(), reinterpret_cast<const CExports::TArea &>(aoi),
111 static_cast<CExports::TInterpolationMode>(interpolation), resimg));
112 });
113 }
114
115 } /* namespace ImageExtensions */
116
120
121 } /* namespace Foundation */
122 CVB_END_INLINE_NS
123} /* namespace Cvb */
124
125#endif
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
The Common Vision Blox image.
Definition decl_image.hpp:50
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:247
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
Rectangle object.
Definition rect.hpp:24
cvbres_t AreaSubImage(IMG ImgIn, TArea Area, TInterpolationMode Interpolation, IMG &ImgOut)
cvbres_t InitializeImageRect(IMG ImgIn, long left, long top, long right, long bottom, double *ValuesIn)
Namespace for collection of image extension functions from the Foundation package.
Definition image_extensions.hpp:31
std::unique_ptr< Image > SubImage(const Image &image, Area2D aoi, Interpolation interpolation=Interpolation::Linear)
Extract the content of an AOI (area of interest) into a new image.
Definition image_extensions.hpp:100
TypedRange< void, double, RANGE >::type InitImage(Image &image, const RANGE &values)
Initialize the planes of this image to different values.
Definition image_extensions.hpp:74
TypedRange< void, double, RANGE >::type InitAOI(Image &image, Rect< int > aoi, const RANGE &values)
Initialize the planes of AOI (area of interest) in this image to different values.
Definition image_extensions.hpp:43
Interpolation
Interpolation modes available inside the Foundation package.
Definition transform_2d.hpp:59
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