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();
585 struct PrivateTag {};
590 : handle_(std::move(guard)),
591 coefficientsTransX_(), coefficientsTransY_(), coefficientsInvTransX_(), coefficientsInvTransY_()
594 auto numCoefficients = CVB_CALL_CAPI (NLTransformNumCoefficients(handle_.Handle()));
595 if (numCoefficients < 0)
597 Utilities::SystemInfo::ThrowLastError ();
600 coefficientsTransX_.resize (numCoefficients);
601 coefficientsTransY_.resize (numCoefficients);
602 coefficientsInvTransX_.resize (numCoefficients);
603 coefficientsInvTransY_.resize (numCoefficients);
605 CVB_CALL_CAPI_CHECKED (NLTransformCoefficients(handle_.Handle(), coefficientsTransX_.data(), coefficientsTransY_.data(),
606 coefficientsInvTransX_.data(), coefficientsInvTransY_.data()));
611 static CExports::NLTRANSFORMATION LoadInternal (
const String & fileName)
613 CExports::NLTRANSFORMATION transformation =
nullptr;
615 CVB_CALL_CAPI_CHECKED (LoadNLTransformFileTyped (fileName.c_str(), transformation));
616 return transformation;
645 return std::make_unique<NonLinearTransformation>(fileName);
657 return handle_.Handle();
670 if (!guard.Handle ())
674 return std::make_unique<NonLinearTransformation>(std::move(guard), PrivateTag{});
677 typedef std::function<bool (
int stepsTotal,
int stepsDone)> CreationProgress;
689 template <
class RANGE>
693 auto originalPixelList = Internal::PixelList::FromPoints (originalPixels);
694 auto transformedPixelList = Internal::PixelList::FromPoints (transformedPixels);
697 return Internal::DoResCallObjectOut<NonLinearTransformation>([&](
void* & restrans)
699 return CVB_CALL_CAPI(CreateNLTransform (originalPixelList->Handle (), transformedPixelList->Handle (), order,
700 progressCallback ? CreationProgressCaller :
nullptr, &progressCallback,
754 int gridSpacing,
int minContrast,
double maxRatio,
int order,
Area2D aoi,
758 ExtractCalibrationLists (plane, style, contrast, gridSpacing, minContrast, maxRatio, aoi, original, transformed);
798 int gridSpacing,
int minContrast,
double maxRatio,
int order,
812 return CVB_CALL_CAPI (NLTransformOrder(handle_.Handle()));
822 return coefficientsTransX_;
832 return coefficientsTransY_;
842 return coefficientsInvTransX_;
852 return coefficientsInvTransY_;
863 CVB_CALL_CAPI_CHECKED (WriteNLTransformFileTyped (handle_.Handle(), fileName.c_str()));
877 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
879 return CVB_CALL_CAPI(CreateNLTransformedImage (image.Handle (), handle_.Handle (), targetSize.
Width(), targetSize.
Height(), targetOffset.
X(), targetOffset.
Y(), resimg));
892 double x = point.
X(), y = point.
Y();
893 CVB_CALL_CAPI_CHECKED (ApplyNLTransform(handle_.Handle(), x, y));
913 return Rect<double>(std::min(topLeft.X(), std::min(topRight.X(), std::min(bottomLeft.X(), bottomRight.X()))),
914 std::min(topLeft.Y(), std::min(topRight.Y(), std::min(bottomLeft.Y(), bottomRight.Y()))),
915 std::max(topLeft.X(), std::max(topRight.X(), std::max(bottomLeft.X(), bottomRight.X()))),
916 std::max(topLeft.Y(), std::max(topRight.Y(), std::max(bottomLeft.Y(), bottomRight.Y()))));
926 template <
class RANGE>
930 std::transform (std::begin (points), std::end (points), std::back_inserter (results),
947 return Internal::DoResCallObjectOut<Image>([&](
void* & resimg)
949 return CVB_CALL_CAPI(CreateInverseNLTransformedImage (image.Handle (), handle_.Handle (), targetSize.
Width(), targetSize.
Height(), targetOffset.
X(), targetOffset.
Y(), resimg));
962 double x = point.
X(), y = point.
Y();
963 CVB_CALL_CAPI_CHECKED (ApplyInverseNLTransform(handle_.Handle(), x, y));
974 template <
class RANGE>
978 std::transform (std::begin (points), std::end (points), std::back_inserter (results),
985 static CExports::cvbbool_t __stdcall CreationProgressCaller (
void* pPrivate, CExports::cvbval_t stepsTotal, CExports::cvbval_t stepsDone)
987 CreationProgress *cbk =
reinterpret_cast<CreationProgress*
> (pPrivate);
988 return (*cbk) (
static_cast<int>(stepsTotal),
static_cast<int>(stepsDone));
992 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...