diff --git a/src/openalpr/utility.cpp b/src/openalpr/utility.cpp
index f76f3cb..693fdef 100644
--- a/src/openalpr/utility.cpp
+++ b/src/openalpr/utility.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see .
*/
+#include
+
#include "utility.h"
using namespace cv;
@@ -379,6 +381,36 @@ LineSegment LineSegment::getParallelLine(float distance)
return result;
}
+// Given a contour and a mask, this function determines what percentage of the contour (area)
+// is inside the masked area.
+float getContourAreaPercentInsideMask(cv::Mat mask, std::vector > contours, std::vector hierarchy, int contourIndex)
+{
+
+
+ Mat innerArea = Mat::zeros(mask.size(), CV_8U);
+
+
+ drawContours(innerArea, contours,
+ contourIndex, // draw this contour
+ cv::Scalar(255,255,255), // in
+ CV_FILLED,
+ 8,
+ hierarchy,
+ 2
+ );
+
+
+ int startingPixels = cv::countNonZero(innerArea);
+ //drawAndWait(&innerArea);
+
+ bitwise_and(innerArea, mask, innerArea);
+
+ int endingPixels = cv::countNonZero(innerArea);
+ //drawAndWait(&innerArea);
+
+ return ((float) endingPixels) / ((float) startingPixels);
+
+}
std::string toString(int value)
{
diff --git a/src/openalpr/utility.h b/src/openalpr/utility.h
index 4e95fa5..a2c5b16 100644
--- a/src/openalpr/utility.h
+++ b/src/openalpr/utility.h
@@ -100,6 +100,8 @@ float angleBetweenPoints(cv::Point p1, cv::Point p2);
cv::Size getSizeMaintainingAspect(cv::Mat inputImg, int maxWidth, int maxHeight);
+float getContourAreaPercentInsideMask(cv::Mat mask, std::vector > contours, std::vector hierarchy, int contourIndex);
+
cv::Mat equalizeBrightness(cv::Mat img);
cv::Rect expandRect(cv::Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);