mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 14:07:39 +08:00
Added common utility (getContourAreaPercentInsideMask) to utility class
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <opencv2/core/core.hpp>
|
||||||
|
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
@@ -379,6 +381,36 @@ LineSegment LineSegment::getParallelLine(float distance)
|
|||||||
return result;
|
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<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> 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)
|
std::string toString(int value)
|
||||||
{
|
{
|
||||||
|
@@ -100,6 +100,8 @@ float angleBetweenPoints(cv::Point p1, cv::Point p2);
|
|||||||
|
|
||||||
cv::Size getSizeMaintainingAspect(cv::Mat inputImg, int maxWidth, int maxHeight);
|
cv::Size getSizeMaintainingAspect(cv::Mat inputImg, int maxWidth, int maxHeight);
|
||||||
|
|
||||||
|
float getContourAreaPercentInsideMask(cv::Mat mask, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, int contourIndex);
|
||||||
|
|
||||||
cv::Mat equalizeBrightness(cv::Mat img);
|
cv::Mat equalizeBrightness(cv::Mat img);
|
||||||
|
|
||||||
cv::Rect expandRect(cv::Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
|
cv::Rect expandRect(cv::Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
|
||||||
|
Reference in New Issue
Block a user