From 70ec67f902a3767d93974974b768fa21be1bd885 Mon Sep 17 00:00:00 2001 From: Jan Herling Date: Tue, 1 Oct 2024 20:43:43 -0700 Subject: [PATCH] Allowing to use any pixel format in FeatureDetector::determineHarrisPoints() Summary: $title Reviewed By: enpe Differential Revision: D63717078 fbshipit-source-id: 66e6bcb49ff6e8aa968a7474004ed71c84fe4100 --- impl/ocean/cv/detector/FeatureDetector.cpp | 14 ++++++++++++++ impl/ocean/cv/detector/FeatureDetector.h | 21 +++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/impl/ocean/cv/detector/FeatureDetector.cpp b/impl/ocean/cv/detector/FeatureDetector.cpp index e8aa45139..bb9e8aef1 100644 --- a/impl/ocean/cv/detector/FeatureDetector.cpp +++ b/impl/ocean/cv/detector/FeatureDetector.cpp @@ -181,6 +181,20 @@ Vectors2 FeatureDetector::determineHarrisPoints(const uint8_t* yFrame, const uns return Detector::HarrisCorner::corners2imagePoints(cornersSubRegion); } +Vectors2 FeatureDetector::determineHarrisPoints(const Frame& frame, const SubRegion& subRegion, const unsigned int horizontalBins, const unsigned int verticalBins, const unsigned int strength, Worker* worker, std::vector* strengths) +{ + ocean_assert(frame.isValid()); + + Frame yFrame; + if (!CV::FrameConverter::Comfort::convert(frame, FrameType::FORMAT_Y8, yFrame, CV::FrameConverter::CP_AVOID_COPY_IF_POSSIBLE, worker)) + { + ocean_assert(false && "Invalid pixel format!"); + return Vectors2(); + } + + return determineHarrisPoints(yFrame.constdata(), yFrame.width(), yFrame.height(), yFrame.paddingElements(), subRegion, horizontalBins, verticalBins, strength, worker, strengths); +} + } } diff --git a/impl/ocean/cv/detector/FeatureDetector.h b/impl/ocean/cv/detector/FeatureDetector.h index aa39e91e2..893ab449d 100644 --- a/impl/ocean/cv/detector/FeatureDetector.h +++ b/impl/ocean/cv/detector/FeatureDetector.h @@ -44,13 +44,13 @@ class OCEAN_CV_DETECTOR_EXPORT FeatureDetector /** * Creates a new intensity vector object with undefined vector elements. - * Beware: The elemtns are neither zero nor a specific value! + * Beware: The elements are neither zero nor a specific value! * @see VectorT2::VectorT2() */ inline IntensityVector2(); /** - * Creates a new intensity vector by the given postion and intensity value. + * Creates a new intensity vector by the given position and intensity value. * @param position Vector position * @param intensity Vector intensity */ @@ -84,7 +84,7 @@ class OCEAN_CV_DETECTOR_EXPORT FeatureDetector /** * Determines the points in an 8bit grayscale image with highest Harris corner response votes. - * @param yFrame The 8bit grayscale frame in which the Harris corner respondes have to be determined, must be valid + * @param yFrame The 8bit grayscale frame in which the Harris corner responses have to be determined, must be valid * @param width The width of the frame in pixel, with range [5, infinity) * @param height The height of the frame in pixel, with range [5, infinity) * @param yFramePaddingElements The number of padding elements at the end of each row of yFrame, in elements, with range [0, infinity) @@ -99,7 +99,7 @@ class OCEAN_CV_DETECTOR_EXPORT FeatureDetector /** * Determines strong feature points in a given image, optional a sub-region can be specified in that the points are detected. - * @param yFrame The frame in which the feature points are detected, must have pixel format FORMAT_Y, must be valid + * @param frame The frame in which the feature points are detected, will be converted to a frame with pixel format FORMAT_Y internally, must be valid * @param subRegion Optional sub-region specifying a small image area in that the points are detected, an invalid sub-region to use the entire frame * @param horizontalBins Optional horizontal bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point) * @param verticalBins Optional vertical bins that can be used to distribute the tracked points into array bins (in each bin there will be at most one point) @@ -108,7 +108,7 @@ class OCEAN_CV_DETECTOR_EXPORT FeatureDetector * @param strengths Optional resulting strength values individual for each point * @return The resulting feature points, feature points with high strength value first */ - static inline Vectors2 determineHarrisPoints(const Frame& yFrame, const SubRegion& subRegion = SubRegion(), const unsigned int horizontalBins = 0u, const unsigned int verticalBins = 0u, const unsigned int strength = 30u, Worker* worker = nullptr, std::vector* strengths = nullptr); + static Vectors2 determineHarrisPoints(const Frame& frame, const SubRegion& subRegion = SubRegion(), const unsigned int horizontalBins = 0u, const unsigned int verticalBins = 0u, const unsigned int strength = 30u, Worker* worker = nullptr, std::vector* strengths = nullptr); /** * Determines strong feature points in a given image, optional a sub-region can be specified in that the points are detected. @@ -151,17 +151,6 @@ inline bool FeatureDetector::IntensityVector2::operator<(const IntensityVector2& return vectorIntensity > object.vectorIntensity; } -inline Vectors2 FeatureDetector::determineHarrisPoints(const Frame& yFrame, const SubRegion& subRegion, const unsigned int horizontalBins, const unsigned int verticalBins, const unsigned int strength, Worker* worker, std::vector* strengths) -{ - if (!yFrame.isPixelFormatCompatible(FrameType::FORMAT_Y8)) - { - ocean_assert(false && "Invalid pixel format!"); - return Vectors2(); - } - - return determineHarrisPoints(yFrame.constdata(), yFrame.width(), yFrame.height(), yFrame.paddingElements(), subRegion, horizontalBins, verticalBins, strength, worker, strengths); -} - } }