Skip to content

Commit

Permalink
Replace use of degrees where radians should be in QRCode FinderPatter…
Browse files Browse the repository at this point in the history
…nDetector

Summary: Fixes how cosine value thresholds are calculated.  Also modifies acceptable range of `angleTolerance` parameter for `FinderPatternDetector::extractIndexTriplets()` and cleans up some assert statements..

Reviewed By: janherling

Differential Revision: D60244369

fbshipit-source-id: a5ae51a5d089157982a7ccf5ba5c29339c285baa
  • Loading branch information
leapally authored and facebook-github-bot committed Jul 31, 2024
1 parent 52a2030 commit 872022d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions impl/ocean/cv/detector/qrcodes/FinderPatternDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,12 @@ IndexTriplets FinderPatternDetector::extractIndexTriplets(const FinderPatterns&
ocean_assert(finderPatterns.size() >= 3);
ocean_assert(Numeric::isInsideRange(Scalar(0), distanceScaleTolerance, Scalar(1)));
ocean_assert_and_suppress_unused(Numeric::isInsideRange(Scalar(0), moduleSizeScaleTolerance, Scalar(1)), moduleSizeScaleTolerance);
ocean_assert(angleTolerance >= Numeric::deg2rad(Scalar(0)) && angleTolerance < Numeric::deg2rad(Scalar(90)));
ocean_assert(angleTolerance >= Scalar(0) && angleTolerance < Numeric::pi_4());

IndexTriplets finderPatternTriplets;

const Scalar angleThreshold = Numeric::abs(Numeric::cos(angleTolerance));
const Scalar parallelOrientationTreshold = Numeric::cos(Scalar(0)) - angleThreshold;
const Scalar perpendicularOrientationThreshold = Numeric::cos(Scalar(90)) + angleThreshold;
const Scalar parallelOrientationTreshold = Numeric::cos(angleTolerance);
const Scalar perpendicularOrientationThreshold = Numeric::cos(Numeric::pi_2() - angleTolerance);

for (size_t a = 0; a < finderPatterns.size() - 2; ++a)
{
Expand All @@ -408,7 +407,7 @@ IndexTriplets FinderPatternDetector::extractIndexTriplets(const FinderPatterns&
const Scalar absCosOrientationAB = std::abs(finderPatternA.orientation() * finderPatternB.orientation());
if (absCosOrientationAB <= parallelOrientationTreshold && absCosOrientationAB >= perpendicularOrientationThreshold)
{
ocean_assert(Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) >= Numeric::rad2deg(angleTolerance) && Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) <= (Scalar(90) - Numeric::rad2deg(angleTolerance)));
ocean_assert(Numeric::acos(absCosOrientationAB) >= angleTolerance && Numeric::acos(absCosOrientationAB) <= Numeric::pi_2() - angleTolerance);
continue;
}

Expand Down Expand Up @@ -436,8 +435,8 @@ IndexTriplets FinderPatternDetector::extractIndexTriplets(const FinderPatterns&
if ((absCosOrientationAC <= parallelOrientationTreshold && absCosOrientationAC >= perpendicularOrientationThreshold)
|| (absCosOrientationBC <= parallelOrientationTreshold && absCosOrientationBC >= perpendicularOrientationThreshold))
{
ocean_assert((Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) >= Numeric::rad2deg(angleTolerance) && Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) <= (Scalar(90) - Numeric::rad2deg(angleTolerance)))
|| (Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) >= Numeric::rad2deg(angleTolerance) && Numeric::rad2deg(Numeric::acos(absCosOrientationAB)) <= (Scalar(90) - Numeric::rad2deg(angleTolerance))));
ocean_assert((Numeric::acos(absCosOrientationAC) >= angleTolerance && Numeric::acos(absCosOrientationAC) <= Numeric::pi_2() - angleTolerance)
|| (Numeric::acos(absCosOrientationBC) >= angleTolerance && Numeric::acos(absCosOrientationBC) <= Numeric::pi_2() - angleTolerance));
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion impl/ocean/cv/detector/qrcodes/FinderPatternDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class OCEAN_CV_DETECTOR_QRCODES_EXPORT FinderPatternDetector
* @param finderPatterns The list finder patterns in which 3-tuples forming potential QR code symbols are sought, must be valid, minimum size: 3
* @param distanceScaleTolerance Scale factor that define how much corners of one finder pattern may deviate from the parallel lines of another finder pattern, range: [0, infinity), default: 0.05
* @param moduleSizeScaleTolerance Defines the maximum difference scale of the module size between pairs of finder patterns in order to be considered a match, range: [0, 1], default: 0.35
* @param angleTolerance Defines the maximum difference of the dominant orientation of pairs of finder patterns in order to be considered a match, measured in radian, range: [0, PI/2), default: deg2rad(9)
* @param angleTolerance Defines the maximum difference of the dominant orientation of pairs of finder patterns in order to be considered a match, measured in radian, range: [0, PI/4), default: deg2rad(9)
* @return A list of 3-tuples of finder patterns, will be empty on failure (or if nothing was found)
*/
static IndexTriplets extractIndexTriplets(const FinderPatterns& finderPatterns, const Scalar distanceScaleTolerance = Scalar(0.175), const Scalar moduleSizeScaleTolerance = Scalar(0.35), const Scalar angleTolerance = Numeric::deg2rad(Scalar(9)));
Expand Down

0 comments on commit 872022d

Please sign in to comment.