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)); })
73 Ignore = CExports::POLARITY_DONT_CARE,
103 EdgeResult(
double x,
double y,
double quality,
EdgeType type) noexcept
127 double X() const noexcept
127 double X() const noexcept {
…}
137 double Y() const noexcept
137 double Y() const noexcept {
…}
179 return (lhs.X() != rhs.X()) || (lhs.Y() != rhs.Y()) || (lhs.Quality() != rhs.Quality())
180 || (lhs.Type() != rhs.Type());
193 return (!(lhs != rhs));
215 size_t resultCount = CVB_CALL_CAPI(EdgeResultsCount(hResults));
216 for (
size_t i = 0; i < resultCount; ++i)
220 CVB_CALL_CAPI_CHECKED(
EdgeResult(hResults, i, x, y, q));
227 typedef HandleGuard<void, CVB_CALL_CAPI(ReleaseEdgeResultsVoid)> ReleaseEdgeResultsGuard;
244 Area2D aoi,
double density = 1.0)
251 CExports::TEdgeResult edgeRes = {0};
252 CExports::cvbbool_t success =
false;
256 success = CVB_CALL_CAPI(CFindFirstEdge(
258 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
261 success = CVB_CALL_CAPI(CSFindFirstEdge(
263 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
266 success = CVB_CALL_CAPI(TFindFirstEdge(
268 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
271 success = CVB_CALL_CAPI(TSFindFirstEdge(
273 reinterpret_cast<CExports::TArea &
>(aoi), threshold, type ==
EdgeType::Positive, edgeRes));
277 static_cast<int>(density * 1000.0),
278 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
279 static_cast<CExports::TEdgePolarity
>(type), edgeRes));
287 return EdgeResult(edgeRes.x, edgeRes.y, edgeRes.Quality, type);
307 double density = 1.0)
329 double density = 1.0)
340 CExports::TEdgeResult edgeRes1 = {0};
341 CExports::TEdgeResult edgeRes2 = {0};
342 CExports::cvbbool_t success =
false;
346 success = CVB_CALL_CAPI(
347 CFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
352 success = CVB_CALL_CAPI(
353 CSFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
358 success = CVB_CALL_CAPI(
359 TFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
364 success = CVB_CALL_CAPI(
365 TSFindEdgePair(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
370 success = CVB_CALL_CAPI(OSFindEdgePair(
372 reinterpret_cast<CExports::TArea &
>(aoi), threshold1,
static_cast<CExports::TEdgePolarity
>(type1),
373 edgeRes1, threshold2,
static_cast<CExports::TEdgePolarity
>(type2), edgeRes2));
381 return EdgeResultPair{{edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1},
382 {edgeRes1.x, edgeRes1.y, edgeRes1.Quality, type1}};
404 double threshold1,
EdgeType type2,
double threshold2,
double density = 1.0)
406 return FindEdgePair(plane, mode, type1, threshold1, type2, threshold2,
424 double threshold,
Area2D aoi,
double density = 1.0)
426 return FindEdgePair(plane, mode, type1, threshold, type2, threshold, aoi, density);
442 double threshold,
double density = 1.0)
444 return FindEdgePair(plane, mode, type1, threshold, type2, threshold,
461 double threshold,
Area2D aoi,
double density = 1.0)
471 CExports::EDGERESULTS hEdgeResults =
nullptr;
472 CVB_CALL_CAPI(OSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
473 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
474 static_cast<CExports::TEdgePolarity
>(type), hEdgeResults));
475 Private::ReleaseEdgeResultsGuard hEdgeResHolder(hEdgeResults);
476 return Private::EdgeResultsToArray(hEdgeResults, type);
480 size_t maxEdges = rawResults.size();
481 size_t edgeCount = 0;
485 CVB_CALL_CAPI(CFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
487 maxEdges, rawResults.data(), edgeCount));
490 CVB_CALL_CAPI(CSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
491 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
495 CVB_CALL_CAPI(TFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
497 maxEdges, rawResults.data(), edgeCount));
500 CVB_CALL_CAPI(TSFindAllEdges(plane.
Parent().
Handle(), plane.
Plane(),
static_cast<int>(density * 1000.0),
501 reinterpret_cast<CExports::TArea &
>(aoi), threshold,
509 std::transform(rawResults.begin(), rawResults.begin() + edgeCount, fullResults.begin(),
510 [=](CExports::TEdgeResult raw) { return EdgeResult(raw.x, raw.y, raw.Quality, type); });
526 double threshold,
double density = 1.0)
545 CExports::TEdgeResult edgeRes = {0};
546 auto success = CVB_CALL_CAPI(OSFindBestEdge(
548 reinterpret_cast<CExports::TArea &
>(aoi),
static_cast<CExports::TEdgePolarity
>(type), edgeRes));
552 return EdgeResult(edgeRes.x, edgeRes.y, edgeRes.Quality, type);
587 reinterpret_cast<CExports::TArea &
>(aoi)));
618 Projection(HandleGuard<Projection> &&guard,
ProjectionMode mode) noexcept
635 : Projection(HandleGuard<Projection>(CreateProjectionHandle(plane, aoi, mode, density)), mode)
652 if (Length() != values_.size())
655 Internal::DoBoolCall([&]() {
656 return CVB_CALL_CAPI(
657 CopyDoubleBuffer(
Handle(),
reinterpret_cast<CExports::pDoubleProjection
>(values.data())));
659 values_.swap(values);
669 CExports::PROJECTIONEX projection =
nullptr;
675 CVB_CALL_CAPI_CHECKED(GetNormProjectionEx(plane.
Parent().
Handle(), plane.
Plane(),
676 static_cast<CExports::cvbdensity_t
>(density * 1000.0),
677 reinterpret_cast<CExports::TArea &
>(aoi), projection));
681 static_cast<CExports::cvbdensity_t
>(density * 1000.0),
682 reinterpret_cast<CExports::TArea &
>(aoi), projection));
704 return std::make_unique<Projection>(plane, aoi, mode, density);
716 return handle_.Handle();
745 CExports::EDGERESULTS hResults =
nullptr;
746 CVB_CALL_CAPI_CHECKED(ZeroCrossings(
Handle(), Length(), hResults));
748 Private::ReleaseEdgeResultsGuard hEdgeResHolder(hResults);
761 return Internal::DoBoolCallObjectOut<Projection>(
772 template <
class RANGE>
773 inline typename TypedRange<std::unique_ptr<Projection>, int, RANGE>::type
Filter(
const RANGE &kernel)
775 auto kernelRange = MakeRangeAdapter<int>(kernel, 1);
777 return Internal::DoBoolCallObjectOut<Projection>(
778 [&](
void *&resproj) {
779 return CVB_CALL_CAPI(
Filter(
Handle(),
reinterpret_cast<CExports::cvbval_t *
>(kernelRange.Data()),
780 kernelRange.Size(), resproj));
773 inline typename TypedRange<std::unique_ptr<Projection>, int, RANGE>::type
Filter(
const RANGE &kernel) {
…}
793 return Internal::DoBoolCallObjectOut<Projection>(
809 size_t Length()
const
812 CVB_CALL_CAPI_CHECKED(GetLength(
Handle(), length));
817 HandleGuard<Projection> handle_;
614 class Projection {
…};
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
Edge search result
Definition edge.hpp:93
EdgeType Type() const noexcept
Type of the edge.
Definition edge.hpp:157
double Quality() const noexcept
Quality of detection, depending on the method used.
Definition edge.hpp:147
double Y() const noexcept
Y-position relative to the last line processed.
Definition edge.hpp:137
double X() const noexcept
X-position relative to the last line processed.
Definition edge.hpp:127
static EdgeResult Nothing() noexcept
The edge result returned when nothing has been found.
Definition edge.hpp:117
Projection that the Edge analysis of Common Vision Blox is using.
Definition edge.hpp:615
Projection(const ImagePlane &plane, Area2D aoi, ProjectionMode mode=ProjectionMode::Sum, double density=1.0)
Create a projection object.
Definition edge.hpp:634
static std::unique_ptr< Projection > FromHandle(HandleGuard< Projection > &&guard, ProjectionMode mode)
Creates projection from a classic API handle.
Definition edge.hpp:728
TypedRange< std::unique_ptr< Projection >, int, RANGE >::type Filter(const RANGE &kernel)
Filter this projection using a 1D filter kernel.
Definition edge.hpp:773
std::vector< EdgeResult > CalculateZeroCrossings()
Get all the zero crossings, that are in the projection.
Definition edge.hpp:743
std::unique_ptr< Projection > Derive()
Create derivative of this projection.
Definition edge.hpp:759
ProjectionMode Mode() const noexcept
Gets the mode of the projection.
Definition edge.hpp:802
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:701
std::unique_ptr< Projection > ToAverageProjection()
Create a new averaged projection from this one.
Definition edge.hpp:791
std::vector< ProjectionValue > Values() const
Retrieve the values of the projection.
Definition edge.hpp:650
void * Handle() const noexcept
Classic API PROJECTIONEX handle.
Definition edge.hpp:714
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:433
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
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:460
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:543
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:327
EdgeType
Type of the edges to be searched.
Definition edge.hpp:71
@ Positive
Intensities increase along the scan direction.
Definition edge.hpp:75
@ Ignore
Used for EdgeResult::Nothing and with the 2nd derivative edge detection functions.
Definition edge.hpp:73
@ Negative
Intensities decrease along the scan direction.
Definition edge.hpp:77
ProjectionMode
Options affecting the result of the projection.
Definition edge.hpp:82
@ Sum
Projection value is the sum of all gray values per projection line.
Definition edge.hpp:86
@ Average
Projection value is the average value per projection line.
Definition edge.hpp:84
std::shared_ptr< Projection > ProjectionPtr
Convenience shared pointer for Projection.
Definition edge.hpp:823
bool operator!=(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition edge.hpp:177
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:584
bool operator==(const EdgeResult &lhs, const EdgeResult &rhs) noexcept
Comparison operator for EdgeResult objects.
Definition edge.hpp:191
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:243
EdgeSearchMode
Determines the algorithm for finding an edge.
Definition edge.hpp:49
@ SecondDerivativeSubPixel
Find edges based on the 2nd derivative of the intensities with sub pixel accuracy.
Definition edge.hpp:66
@ Intensity
Find edges based on absolute intensities in the image.
Definition edge.hpp:55
@ IntensitySubPixel
Like Intensity, but with sub pixel accuracy.
Definition edge.hpp:57
@ Contrast
Find edges based on the contrasts in the image (1st derivative of the gray values).
Definition edge.hpp:59
@ ContrastSubPixel
Like Contrast, but with sub pixel accuracy.
Definition edge.hpp:61
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
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:200
EdgeResult Second
Second found edge.
Definition edge.hpp:205
EdgeResult First
First found edge.
Definition edge.hpp:202
Single projection value.
Definition edge.hpp:594
double Value
Projection value as determined by the ProjectionMode.
Definition edge.hpp:603
Point2D< double > Position
Coordinate of the projection.
Definition edge.hpp:600