3#include "../_cexports/c_edge.h"
5#include "../global.hpp"
7#include "../exception.hpp"
9#include "../area_2d.hpp"
31 inline HandleGuard<Foundation::Edge::Projection>::HandleGuard(
void *handle) noexcept
32 : HandleGuard<Foundation::Edge::Projection>(handle, [](
void *h) { CVB_CALL_CAPI(ReleaseProjection(h)); })
78 Ignore = CExports::POLARITY_DONT_CARE,
100 EdgeResult() noexcept
108 EdgeResult(
double x,
double y,
double quality,
EdgeType type) noexcept
132 double X() const noexcept
142 double Y() const noexcept
184 return (lhs.X() != rhs.X()) || (lhs.Y() != rhs.Y()) || (lhs.Quality() != rhs.Quality())
185 || (lhs.Type() != rhs.Type());
198 return (!(lhs != rhs));
220 size_t resultCount = CVB_CALL_CAPI(EdgeResultsCount(hResults));
221 for (
size_t i = 0; i < resultCount; ++i)
225 CVB_CALL_CAPI_CHECKED(
EdgeResult(hResults, i, x, y, q));
232 typedef HandleGuard<void, CVB_CALL_CAPI(ReleaseEdgeResultsVoid)> ReleaseEdgeResultsGuard;
249 Area2D aoi,
double density = 1.0)
256 CExports::TEdgeResult edgeRes = {0};
257 CExports::cvbbool_t success =
false;
261 success = CVB_CALL_CAPI(CFindFirstEdge(
263 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
266 success = CVB_CALL_CAPI(CSFindFirstEdge(
268 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
271 success = CVB_CALL_CAPI(TFindFirstEdge(
273 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
276 success = CVB_CALL_CAPI(TSFindFirstEdge(
278 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
282 static_cast<int>(density * 1000.0),
283 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
284 static_cast<CExports::TEdgePolarity
>(type), edgeRes));
292 return EdgeResult(edgeRes.x, edgeRes.y, edgeRes.Quality, type);
312 double density = 1.0)
334 double density = 1.0)
345 CExports::TEdgeResult edgeRes1 = {0};
346 CExports::TEdgeResult edgeRes2 = {0};
347 CExports::cvbbool_t success =
false;
351 success = CVB_CALL_CAPI(
352 CFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
357 success = CVB_CALL_CAPI(
358 CSFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
363 success = CVB_CALL_CAPI(
364 TFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
369 success = CVB_CALL_CAPI(
370 TSFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
375 success = CVB_CALL_CAPI(OSFindEdgePair(
377 reinterpret_cast<CExports::TArea &
>(aoi), threshold1,
static_cast<CExports::TEdgePolarity
>(type1),
378 edgeRes1, threshold2,
static_cast<CExports::TEdgePolarity
>(type2), edgeRes2));
386 return EdgeResultPair{{edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1},
387 {edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1}};
409 double threshold1,
EdgeType type2,
double threshold2,
double density = 1.0)
411 return FindEdgePair(plane, mode, type1, threshold1, type2, threshold2,
429 double threshold,
Area2D aoi,
double density = 1.0)
431 return FindEdgePair(plane, mode, type1, threshold, type2, threshold, aoi, density);
447 double threshold,
double density = 1.0)
449 return FindEdgePair(plane, mode, type1, threshold, type2, threshold,
466 double threshold,
Area2D aoi,
double density = 1.0)
476 CExports::EDGERESULTS hEdgeResults =
nullptr;
477 CVB_CALL_CAPI(OSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
478 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
479 static_cast<CExports::TEdgePolarity
>(type), hEdgeResults));
480 Private::ReleaseEdgeResultsGuard hEdgeResHolder(hEdgeResults);
481 return Private::EdgeResultsToArray(hEdgeResults, type);
485 size_t maxEdges = rawResults.size();
486 size_t edgeCount = 0;
490 CVB_CALL_CAPI(CFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
492 maxEdges, rawResults.data(), edgeCount));
495 CVB_CALL_CAPI(CSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
496 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
500 CVB_CALL_CAPI(TFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
502 maxEdges, rawResults.data(), edgeCount));
505 CVB_CALL_CAPI(TSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
506 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
514 std::transform(rawResults.begin(), rawResults.begin() + edgeCount, fullResults.begin(),
515 [=](CExports::TEdgeResult raw) { return EdgeResult(raw.x, raw.y, raw.Quality, type); });
531 double threshold,
double density = 1.0)
550 CExports::TEdgeResult edgeRes = {0};
551 auto success = CVB_CALL_CAPI(OSFindBestEdge(
553 reinterpret_cast<CExports::TArea &
>(aoi),
static_cast<CExports::TEdgePolarity
>(type), edgeRes));
557 return EdgeResult(edgeRes.x, edgeRes.y, edgeRes.Quality, type);
592 reinterpret_cast<CExports::TArea &
>(aoi)));
623 Projection(HandleGuard<Projection> &&guard,
ProjectionMode mode) noexcept
640 : Projection(HandleGuard<Projection>(CreateProjectionHandle(plane, aoi, mode, density)), mode)
657 if (Length() != values_.size())
660 Internal::DoBoolCall([&]() {
661 return CVB_CALL_CAPI(
662 CopyDoubleBuffer(
Handle(),
reinterpret_cast<CExports::pDoubleProjection
>(values.data())));
664 values_.swap(values);
674 CExports::PROJECTIONEX projection =
nullptr;
680 CVB_CALL_CAPI_CHECKED(GetNormProjectionEx(plane.
Parent().
Handle(), plane.
Plane(),
681 static_cast<CExports::cvbdensity_t
>(density * 1000.0),
682 reinterpret_cast<CExports::TArea &
>(aoi), projection));
686 static_cast<CExports::cvbdensity_t
>(density * 1000.0),
687 reinterpret_cast<CExports::TArea &
>(aoi), projection));
709 return std::make_unique<Projection>(plane, aoi, mode, density);
721 return handle_.Handle();
750 CExports::EDGERESULTS hResults =
nullptr;
751 CVB_CALL_CAPI_CHECKED(ZeroCrossings(
Handle(), Length(), hResults));
753 Private::ReleaseEdgeResultsGuard hEdgeResHolder(hResults);
766 return Internal::DoBoolCallObjectOut<Projection>(
777 template <
class RANGE>
778 inline typename TypedRange<std::unique_ptr<Projection>, int, RANGE>::type
Filter(
const RANGE &kernel)
780 auto kernelRange = MakeRangeAdapter<int>(kernel, 1);
782 return Internal::DoBoolCallObjectOut<Projection>(
783 [&](
void *&resproj) {
784 return CVB_CALL_CAPI(
Filter(
Handle(),
reinterpret_cast<CExports::cvbval_t *
>(kernelRange.Data()),
785 kernelRange.Size(), resproj));
798 return Internal::DoBoolCallObjectOut<Projection>(
814 size_t Length()
const
817 CVB_CALL_CAPI_CHECKED(GetLength(
Handle(), length));
822 HandleGuard<Projection> handle_;
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
Size2D< double > Size() const noexcept
Size (width and height) of the area of interest.
Definition area_2d.hpp:182
Edge search result
Definition edge.hpp:98
EdgeType Type() const noexcept
Type of the edge.
Definition edge.hpp:162
double Quality() const noexcept
Quality of detection, depending on the method used.
Definition edge.hpp:152
double Y() const noexcept
Y-position relative to the last line processed.
Definition edge.hpp:142
double X() const noexcept
X-position relative to the last line processed.
Definition edge.hpp:132
static EdgeResult Nothing() noexcept
The edge result returned when nothing has been found.
Definition edge.hpp:122
Projection that the Edge analysis of Common Vision Blox is using.
Definition edge.hpp:620
Projection(const ImagePlane &plane, Area2D aoi, ProjectionMode mode=ProjectionMode::Sum, double density=1.0)
Create a projection object.
Definition edge.hpp:639
static std::unique_ptr< Projection > FromHandle(HandleGuard< Projection > &&guard, ProjectionMode mode)
Creates projection from a classic API handle.
Definition edge.hpp:733
TypedRange< std::unique_ptr< Projection >, int, RANGE >::type Filter(const RANGE &kernel)
Filter this projection using a 1D filter kernel.
Definition edge.hpp:778
std::vector< EdgeResult > CalculateZeroCrossings()
Get all the zero crossings, that are in the projection.
Definition edge.hpp:748
std::unique_ptr< Projection > Derive()
Create derivative of this projection.
Definition edge.hpp:764
ProjectionMode Mode() const noexcept
Gets the mode of the projection.
Definition edge.hpp:807
static std::unique_ptr< Projection > Create(const ImagePlane &plane, Area2D aoi, ProjectionMode mode=ProjectionMode::Sum, double density=1.0)
Create a projection object.
Definition edge.hpp:706
std::unique_ptr< Projection > ToAverageProjection()
Create a new averaged projection from this one.
Definition edge.hpp:796
std::vector< ProjectionValue > Values() const
Retrieve the values of the projection.
Definition edge.hpp:655
void * Handle() const noexcept
Classic API PROJECTIONEX handle.
Definition edge.hpp:719
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
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Rectangle object.
Definition rect.hpp:24
Collection of functions for edge detection.
Definition edge.hpp:25
std::vector< EdgeResult > FindAllEdges(const ImagePlane &plane, EdgeSearchMode mode, EdgeType type, double threshold, Area2D aoi, double density=1.0)
Find all edges inside the aoi.
Definition edge.hpp:465
EdgeResult FindBestEdge(const ImagePlane &plane, EdgeType type, Area2D aoi, double density=1.0)
Use the 2nd derivative method to find the edge with the highest intensity in the area of interest.
Definition edge.hpp:548
EdgeResultPair FindEdgePair(const ImagePlane &plane, EdgeSearchMode mode, EdgeType type1, double threshold1, EdgeType type2, double threshold2, Area2D aoi, double density=1.0)
Find an edge pair (as specified) in the aoi.
Definition edge.hpp:332
EdgeType
Type of the edges to be searched.
Definition edge.hpp:76
@ Positive
Intensities increase along the scan direction.
Definition edge.hpp:80
@ Ignore
Used for EdgeResult::Nothing and with the 2nd derivative edge detection functions.
Definition edge.hpp:78
@ Negative
Intensities decrease along the scan direction.
Definition edge.hpp:82
ProjectionMode
Options affecting the result of the projection.
Definition edge.hpp:87
@ Sum
Projection value is the sum of all gray values per projection line.
Definition edge.hpp:91
@ Average
Projection value is the average value per projection line.
Definition edge.hpp:89
std::shared_ptr< Projection > ProjectionPtr
Convenience shared pointer for Projection.
Definition edge.hpp:828
bool operator!=(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition edge.hpp:182
void WriteProjection(const ImagePlane &plane, Area2D aoi, double density=1.0)
Write the projection that Edge is using internally as the basis for its calculations into an image pl...
Definition edge.hpp:589
bool operator==(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition edge.hpp:196
EdgeResult FindFirstEdge(const ImagePlane &plane, EdgeSearchMode mode, EdgeType type, double threshold, Area2D aoi, double density=1.0)
Find the first edge (as specified) in the aoi.
Definition edge.hpp:248
EdgeSearchMode
Determines the algorithm for finding an edge.
Definition edge.hpp:54
@ SecondDerivativeSubPixel
Find edges based on the 2nd derivative of the intensities with sub pixel accuracy.
Definition edge.hpp:71
@ Intensity
Find edges based on absolute intensities in the image.
Definition edge.hpp:60
@ IntensitySubPixel
Like Intensity, but with sub pixel accuracy.
Definition edge.hpp:62
@ Contrast
Find edges based on the contrasts in the image (1st derivative of the gray values).
Definition edge.hpp:64
@ ContrastSubPixel
Like Contrast, but with sub pixel accuracy.
Definition edge.hpp:66
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition version.hpp:11
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition point_2d.hpp:371
A pair of found edges.
Definition edge.hpp:205
EdgeResult Second
Second found edge.
Definition edge.hpp:210
EdgeResult First
First found edge.
Definition edge.hpp:207
Single projection value.
Definition edge.hpp:599
double Value
Projection value as determined by the ProjectionMode.
Definition edge.hpp:608
Point2D< double > Position
Coordinate of the projection.
Definition edge.hpp:605