5#include "../_cexports/c_foundation.h"
7#include "../global.hpp"
9#include "../exception.hpp"
10#include "../size_2d.hpp"
11#include "../angle.hpp"
12#include "../matrix_2d.hpp"
13#include "../point_2d.hpp"
15#include "../string.hpp"
16#include "../_detail/detail_pixel_list.hpp"
17#include "../area_2d.hpp"
34inline HandleGuard<Foundation::Transform2D::NonLinearTransformation>::HandleGuard(
void * handle) noexcept
35 : HandleGuard<Foundation::Transform2D::NonLinearTransformation>(handle, [](
void* h) { CVB_CALL_CAPI(ReleaseObject(h)); })
58 NearestNeighbor = CExports::IP_NearestNeighbour,
61 Linear = CExports::IP_Linear,
64 Cubic = CExports::IP_Cubic,
109 CVB_CALL_CAPI_CHECKED(CalcPerspectiveTransformation (destRect.
Left(), destRect.
Top(), destRect.
Right(), destRect.
Bottom(),
110 leftTop.
X(), leftTop.
Y(), rightTop.
X(), rightTop.
Y(),
111 rightBottom.
X(), rightBottom.
Y(), leftBottom.
X(), leftBottom.
Y(),
112 c00_, c01_, c02_, c10_, c11_, c12_, c20_, c21_, c22_));
127 CVB_CALL_CAPI_CHECKED(CalcPerspectiveTransformationEx (destRect.
Left(), destRect.
Top(), destRect.
Right(), destRect.
Bottom(),
128 leftTop.
X(), leftTop.
Y(), rightTop.
X(), rightTop.
Y(),
129 rightBottom.
X(), rightBottom.
Y(), leftBottom.
X(), leftBottom.
Y(),
130 c00_, c01_, c02_, c10_, c11_, c12_, c20_, c21_, c22_));
138 double C00() const noexcept
148 double C01() const noexcept
158 double C02() const noexcept
168 double C10() const noexcept
178 double C11() const noexcept
188 double C12() const noexcept
198 double C20() const noexcept
208 double C21() const noexcept
218 double C22() const noexcept
249 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
252 return CVB_CALL_CAPI(MatrixTransformImage (image.Handle (),
reinterpret_cast<const CExports::TMatrix&
>(matrix),
253 static_cast<CExports::TInterpolationMode
>(interpolation), resimg));
267 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
286 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
288 return CVB_CALL_CAPI(PerspectiveTransformImage (image.Handle (), targetSize.
Width(), targetSize.
Height(), 0, 0,
290 static_cast<CExports::TInterpolationMode
>(interpolation), resimg));
305 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
307 return CVB_CALL_CAPI(ResizeImage (image.Handle (), targetSize.
Width(), targetSize.
Height(),
308 static_cast<CExports::TInterpolationMode
>(interpolation), resimg));
323 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
325 return CVB_CALL_CAPI(RotateImage (image.Handle (), angle.
Deg(),
326 static_cast<CExports::TInterpolationMode
>(interpolation), resimg));
342 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
344 return CVB_CALL_CAPI(ShearImage (image.Handle (), shearX, shearY,
345 static_cast<CExports::TInterpolationMode
>(interpolation), resimg));
407 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
410 static_cast<CExports::TCalibrationPatternStyle
>(style),
static_cast<CExports::TCalibrationPatternContrast
>(contrast),
448 int numColumns,
int numRows,
double horizontalBorder,
double verticalBorder,
int dpi)
450 return Internal::DoResCallObjectOut<Image> ([&](
void* & resimg)
456 static_cast<CExports::TCalibrationPatternStyle
>(style),
static_cast<CExports::TCalibrationPatternContrast
>(contrast),
460 static_cast<CExports::TCalibrationPatternStyle
>(style),
static_cast<CExports::TCalibrationPatternContrast
>(contrast),
522 CExports::PIXELLIST originalPixelList =
nullptr;
523 CExports::PIXELLIST transformedPixelList =
nullptr;
525 CVB_CALL_CAPI_CHECKED (GetCalibrationLists (plane.Parent().Handle(), plane.Plane(),
static_cast<CExports::TCalibrationPatternStyle
>(style),
static_cast<CExports::TCalibrationPatternContrast
>(contrast),
526 reinterpret_cast<CExports::TArea&
>(aoi), gridSpacing, minContrast, maxRatio, originalPixelList, transformedPixelList));
527 HandleGuard<Internal::PixelList> originalGuard(originalPixelList);
528 HandleGuard<Internal::PixelList> transformedGuard(transformedPixelList);
530 originalPixels = Internal::PixelList::FromHandle(std::move(originalGuard))->ToPoints();
531 transformedPixels = Internal::PixelList::FromHandle(std::move(transformedGuard))->ToPoints();
588 : handle_(std::move(guard)),
589 coefficientsTransX_(), coefficientsTransY_(), coefficientsInvTransX_(), coefficientsInvTransY_()
592 auto numCoefficients = CVB_CALL_CAPI (NLTransformNumCoefficients(handle_.Handle()));
593 if (numCoefficients < 0)
595 Utilities::SystemInfo::ThrowLastError ();
598 coefficientsTransX_.resize (numCoefficients);
599 coefficientsTransY_.resize (numCoefficients);
600 coefficientsInvTransX_.resize (numCoefficients);
601 coefficientsInvTransY_.resize (numCoefficients);
603 CVB_CALL_CAPI_CHECKED (NLTransformCoefficients(handle_.Handle(), coefficientsTransX_.data(), coefficientsTransY_.data(),
604 coefficientsInvTransX_.data(), coefficientsInvTransY_.data()));
608 static CExports::NLTRANSFORMATION LoadInternal (
const String & fileName)
610 CExports::NLTRANSFORMATION transformation =
nullptr;
612 CVB_CALL_CAPI_CHECKED (LoadNLTransformFileTyped (fileName.c_str(), transformation));
613 return transformation;
655 return handle_.Handle();
668 if (!guard.Handle ())
675 typedef std::function<bool (
int stepsTotal,
int stepsDone)> CreationProgress;
687 template <
class RANGE>
691 auto originalPixelList = Internal::PixelList::FromPoints (originalPixels);
692 auto transformedPixelList = Internal::PixelList::FromPoints (transformedPixels);
695 return Internal::DoResCallObjectOut<NonLinearTransformation>([&](
void* & restrans)
697 return CVB_CALL_CAPI(CreateNLTransform (originalPixelList->Handle (), transformedPixelList->Handle (), order,
698 progressCallback ? CreationProgressCaller :
nullptr, &progressCallback,
752 int gridSpacing,
int minContrast,
double maxRatio,
int order,
Area2D aoi,
756 ExtractCalibrationLists (plane, style, contrast, gridSpacing, minContrast, maxRatio, aoi, original, transformed);
796 int gridSpacing,
int minContrast,
double maxRatio,
int order,
810 return CVB_CALL_CAPI (NLTransformOrder(handle_.Handle()));
820 return coefficientsTransX_;
830 return coefficientsTransY_;
840 return coefficientsInvTransX_;
850 return coefficientsInvTransY_;
861 CVB_CALL_CAPI_CHECKED (WriteNLTransformFileTyped (handle_.Handle(), fileName.c_str()));
875 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
877 return CVB_CALL_CAPI(CreateNLTransformedImage (image.Handle (), handle_.Handle (), targetSize.
Width(), targetSize.
Height(), targetOffset.
X(), targetOffset.
Y(), resimg));
890 double x = point.
X(), y = point.
Y();
891 CVB_CALL_CAPI_CHECKED (ApplyNLTransform(handle_.Handle(), x, y));
911 return Rect<double>(std::min(topLeft.X(), std::min(topRight.X(), std::min(bottomLeft.X(), bottomRight.X()))),
912 std::min(topLeft.Y(), std::min(topRight.Y(), std::min(bottomLeft.Y(), bottomRight.Y()))),
913 std::max(topLeft.X(), std::max(topRight.X(), std::max(bottomLeft.X(), bottomRight.X()))),
914 std::max(topLeft.Y(), std::max(topRight.Y(), std::max(bottomLeft.Y(), bottomRight.Y()))));
924 template <
class RANGE>
928 std::transform (std::begin (points), std::end (points), std::back_inserter (results),
945 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
947 return CVB_CALL_CAPI(CreateInverseNLTransformedImage (image.Handle (), handle_.Handle (), targetSize.
Width(), targetSize.
Height(), targetOffset.
X(), targetOffset.
Y(), resimg));
960 double x = point.
X(), y = point.
Y();
961 CVB_CALL_CAPI_CHECKED (ApplyInverseNLTransform(handle_.Handle(), x, y));
972 template <
class RANGE>
976 std::transform (std::begin (points), std::end (points), std::back_inserter (results),
983 static CExports::cvbbool_t __stdcall CreationProgressCaller (
void* pPrivate, CExports::cvbval_t stepsTotal, CExports::cvbval_t stepsDone)
985 CreationProgress *cbk =
reinterpret_cast<CreationProgress*
> (pPrivate);
986 return (*cbk) (
static_cast<int>(stepsTotal),
static_cast<int>(stepsDone));
990 HandleGuard<NonLinearTransformation> handle_;
Object for convenient and type - safe handling of angles.
Definition: angle.hpp:19
double Deg() const noexcept
Get the value in degrees.
Definition: angle.hpp:87
Structure that represents an area of interest in the image.
Definition: area_2d.hpp:21
The Common Vision Blox image.
Definition: decl_image.hpp:45
Image plane information container.
Definition: decl_image_plane.hpp:33
Double precision 2x2 matrix class.
Definition: matrix_2d.hpp:16
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
T Bottom() const noexcept
Gets bottom row of the rectangle (still inside the rectangle).
Definition: rect.hpp:151
T Top() const noexcept
Gets first row of the rectangle.
Definition: rect.hpp:111
T Right() const noexcept
Gets rightmost column of the rectangle (still inside the rectangle).
Definition: rect.hpp:131
T Left() const noexcept
Gets first column of the rectangle.
Definition: rect.hpp:91
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
@ X
Sensor pixel values are mirrored in X (or denoted by u), so that the columns of the range map will be...
@ Y
Sensor pixel values are mirrored in Y (or denoted by v), so that the range map pixel values will be f...