3#include "../_cexports/c_edge.h"
5#include "../global.hpp"
7#include "../exception.hpp"
9#include "../area_2d.hpp"
24namespace Foundation {
namespace Edge {
class Projection; } }
27inline HandleGuard<Foundation::Edge::Projection>::HandleGuard(
void * handle) noexcept
28 : HandleGuard<Foundation::Edge::Projection>(handle, [](
void* h) { CVB_CALL_CAPI(ReleaseProjection(h)); })
71 Ignore = CExports::POLARITY_DONT_CARE,
73 Positive = CExports::POLARITY_POSITIVE,
75 Negative = CExports::POLARITY_NEGATIVE
98 : x_ (x), y_ (y), quality_ (quality), type_ (type)
117 double X () const noexcept
127 double Y () const noexcept
169 return (lhs.X() != rhs.X()) || (lhs.Y() != rhs.Y()) || (lhs.Quality() != rhs.Quality()) || (lhs.Type() != rhs.Type());
182 return (!(lhs != rhs));
204 size_t resultCount = CVB_CALL_CAPI (EdgeResultsCount (hResults));
205 for (
size_t i = 0; i < resultCount; ++i)
208 CVB_CALL_CAPI_CHECKED (
EdgeResult (hResults, i, x, y, q));
209 results.push_back (
EdgeResult(x, y, q, type));
215typedef HandleGuard<void, CVB_CALL_CAPI(ReleaseEdgeResultsVoid)> ReleaseEdgeResultsGuard;
238 CExports::TEdgeResult edgeRes = { 0 };
239 CExports::cvbbool_t success =
false;
243 success = CVB_CALL_CAPI (CFindFirstEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
246 success = CVB_CALL_CAPI (CSFindFirstEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
249 success = CVB_CALL_CAPI (TFindFirstEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
252 success = CVB_CALL_CAPI (TSFindFirstEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
255 success = CVB_CALL_CAPI (OSFindFirstEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold,
static_cast<CExports::TEdgePolarity
>(type), edgeRes));
263 return EdgeResult (edgeRes.x, edgeRes.y, edgeRes.Quality, type);
312 CExports::TEdgeResult edgeRes1 = { 0 };
313 CExports::TEdgeResult edgeRes2 = { 0 };
314 CExports::cvbbool_t success =
false;
318 success = CVB_CALL_CAPI (CFindEdgePair(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold1, type1 ==
EdgeType::Positive, edgeRes1, threshold2, type2 ==
EdgeType::Positive, edgeRes2));
321 success = CVB_CALL_CAPI (CSFindEdgePair(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold1, type1 ==
EdgeType::Positive, edgeRes1, threshold2, type2 ==
EdgeType::Positive, edgeRes2));
324 success = CVB_CALL_CAPI (TFindEdgePair(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold1, type1 ==
EdgeType::Positive, edgeRes1, threshold2, type2 ==
EdgeType::Positive, edgeRes2));
327 success = CVB_CALL_CAPI (TSFindEdgePair(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold1, type1 ==
EdgeType::Positive, edgeRes1, threshold2, type2 ==
EdgeType::Positive, edgeRes2));
330 success = CVB_CALL_CAPI (OSFindEdgePair(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold1,
static_cast<CExports::TEdgePolarity
>(type1), edgeRes1, threshold2,
static_cast<CExports::TEdgePolarity
>(type2), edgeRes2));
338 return EdgeResultPair { {edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1},
339 {edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1} };
380 return FindEdgePair (plane, mode, type1, threshold, type2, threshold, aoi, density);
423 CExports::EDGERESULTS hEdgeResults =
nullptr;
424 CVB_CALL_CAPI (OSFindAllEdges(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold,
static_cast<CExports::TEdgePolarity
>(type), hEdgeResults));
425 Private::ReleaseEdgeResultsGuard hEdgeResHolder (hEdgeResults);
426 return Private::EdgeResultsToArray(hEdgeResults, type);
430 size_t maxEdges = rawResults.size ();
431 size_t edgeCount = 0;
435 CVB_CALL_CAPI (CFindAllEdges(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, maxEdges, rawResults.data(), edgeCount));
438 CVB_CALL_CAPI (CSFindAllEdges(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, maxEdges, rawResults.data(), edgeCount));
441 CVB_CALL_CAPI (TFindAllEdges(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, maxEdges, rawResults.data(), edgeCount));
444 CVB_CALL_CAPI (TSFindAllEdges(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi), threshold, type ==
EdgeType::Positive, maxEdges, rawResults.data(), edgeCount));
451 std::transform (rawResults.begin (), rawResults.begin () + edgeCount, fullResults.begin (),
452 [=](CExports::TEdgeResult raw) { return EdgeResult (raw.x, raw.y, raw.Quality, type); });
484 CExports::TEdgeResult edgeRes = { 0 };
485 auto success = CVB_CALL_CAPI (OSFindBestEdge(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi),
static_cast<CExports::TEdgePolarity
>(type), edgeRes));
489 return EdgeResult (edgeRes.x, edgeRes.y, edgeRes.Quality, type);
521 CVB_CALL_CAPI (
WriteProjection(plane.Parent().Handle(), plane.Plane(),
static_cast<int>(density * 1000.0),
reinterpret_cast<CExports::TArea&
>(aoi)));
553 : handle_(std::move(guard)),
568 :
Projection (HandleGuard<
Projection>(CreateProjectionHandle (plane, aoi, mode, density)), mode)
586 if (Length() != values_.size())
589 Internal::DoBoolCall([&]()
591 return CVB_CALL_CAPI(CopyDoubleBuffer(
Handle(),
reinterpret_cast<CExports::pDoubleProjection
>(values.data())));
593 values_.swap(values);
602 CExports::PROJECTIONEX projection =
nullptr;
607 CVB_CALL_CAPI_CHECKED (GetNormProjectionEx(plane.Parent().Handle(), plane.Plane(),
static_cast<CExports::cvbdensity_t
>(density * 1000.0),
608 reinterpret_cast<CExports::TArea&
>(aoi), projection));
611 CVB_CALL_CAPI_CHECKED (GetProjectionEx(plane.Parent().Handle(), plane.Plane(),
static_cast<CExports::cvbdensity_t
>(density * 1000.0),
612 reinterpret_cast<CExports::TArea&
>(aoi), projection));
632 return std::make_unique<Projection>(plane, aoi, mode, density);
644 return handle_.Handle();
658 if (!guard.Handle ())
673 CExports::EDGERESULTS hResults =
nullptr;
674 CVB_CALL_CAPI_CHECKED (ZeroCrossings (
Handle(), Length(), hResults));
676 Private::ReleaseEdgeResultsGuard hEdgeResHolder (hResults);
689 return Internal::DoBoolCallObjectOut<Projection>([&](
void* & resproj)
691 return CVB_CALL_CAPI(Derivation (
Handle (), resproj));
703 template <
class RANGE>
706 auto kernelRange = MakeRangeAdapter<int> (kernel, 1);
708 return Internal::DoBoolCallObjectOut<Projection>([&](
void* & resproj)
710 return CVB_CALL_CAPI(
Filter (
Handle (),
reinterpret_cast<CExports::cvbval_t *
>(kernelRange.Data()),
711 kernelRange.Size(), resproj));
724 return Internal::DoBoolCallObjectOut<Projection>([&](
void* & resproj)
726 return CVB_CALL_CAPI(Normalize (
Handle (), resproj));
743 size_t Length ()
const
746 CVB_CALL_CAPI_CHECKED (GetLength (
Handle(), length));
751 HandleGuard<Projection> handle_;
Structure that represents an area of interest in the image.
Definition: area_2d.hpp:21
Edge search result
Definition: edge.hpp:91
EdgeType Type() const noexcept
Type of the edge.
Definition: edge.hpp:147
double Quality() const noexcept
Quality of detection, depending on the method used.
Definition: edge.hpp:137
double Y() const noexcept
Y-position relative to the last line processed.
Definition: edge.hpp:127
double X() const noexcept
X-position relative to the last line processed.
Definition: edge.hpp:117
static EdgeResult Nothing() noexcept
The edge result returned when nothing has been found.
Definition: edge.hpp:107
Projection that the Edge analysis of Common Vision Blox is using.
Definition: edge.hpp:549
Projection(const ImagePlane &plane, Area2D aoi, ProjectionMode mode=ProjectionMode::Sum, double density=1.0)
Create a projection object.
Definition: edge.hpp:567
static std::unique_ptr< Projection > FromHandle(HandleGuard< Projection > &&guard, ProjectionMode mode)
Creates projection from a classic API handle.
Definition: edge.hpp:656
TypedRange< std::unique_ptr< Projection >, int, RANGE >::type Filter(const RANGE &kernel)
Filter this projection using a 1D filter kernel.
Definition: edge.hpp:704
std::vector< EdgeResult > CalculateZeroCrossings()
Get all the zero crossings, that are in the projection.
Definition: edge.hpp:671
std::unique_ptr< Projection > Derive()
Create derivative of this projection.
Definition: edge.hpp:687
ProjectionMode Mode() const noexcept
Gets the mode of the projection.
Definition: edge.hpp:736
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:630
std::unique_ptr< Projection > ToAverageProjection()
Create a new averaged projection from this one.
Definition: edge.hpp:722
std::vector< ProjectionValue > Values() const
Retrieve the values of the projection.
Definition: edge.hpp:584
void * Handle() const noexcept
Classic API PROJECTIONEX handle.
Definition: edge.hpp:642
Image plane information container.
Definition: decl_image_plane.hpp:33
Rectangle object.
Definition: rect.hpp:26
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:413
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:482
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:301
EdgeType
Type of the edges to be searched.
Definition: edge.hpp:69
@ Positive
Intensities increase along the scan direction.
@ Ignore
Used for EdgeResult::Nothing and with the 2nd derivative edge detection functions.
@ Negative
Intensities decrease along the scan direction.
ProjectionMode
Options affecting the result of the projection.
Definition: edge.hpp:80
@ Sum
Projection value is the sum of all gray values per projection line.
@ Average
Projection value is the average value per projection line.
std::shared_ptr< Projection > ProjectionPtr
Convenience shared pointer for Projection.
Definition: edge.hpp:757
bool operator!=(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition: edge.hpp:167
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:519
bool operator==(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition: edge.hpp:180
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:231
EdgeSearchMode
Determines the algorithm for finding an edge.
Definition: edge.hpp:47
@ SecondDerivativeSubPixel
Find edges based on the 2nd derivative of the intensities with sub pixel accuracy.
@ Intensity
Find edges based on absolute intensities in the image.
@ IntensitySubPixel
Like Intensity, but with sub pixel accuracy.
@ Contrast
Find edges based on the contrasts in the image (1st derivative of the gray values).
@ ContrastSubPixel
Like Contrast, but with sub pixel accuracy.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition: point_2d.hpp:380
A pair of found edges.
Definition: edge.hpp:189
EdgeResult Second
Second found edge.
Definition: edge.hpp:194
EdgeResult First
First found edge.
Definition: edge.hpp:191
Single projection value.
Definition: edge.hpp:528
double Value
Projection value as determined by the ProjectionMode.
Definition: edge.hpp:537
Point2D< double > Position
Coordinate of the projection.
Definition: edge.hpp:534