Added new features

This commit is contained in:
2017-12-20 16:41:32 +01:00
parent 6c3eeac6fb
commit f1b60e4fcb
12 changed files with 323 additions and 140 deletions
+12 -1
View File
@@ -16,6 +16,7 @@ FeatureExtractor::~FeatureExtractor()
void FeatureExtractor::Extract(Mat &ref)
{
//Bepaal verschillende features
double ar = AspectRatio();
double cr = Circularity();
double bendingEnergy = getBendingEnergy();
@@ -24,10 +25,10 @@ void FeatureExtractor::Extract(Mat &ref)
double perimeter = getPerimeter();
double numDefects = convexDefects();
//ref = (Mat_<double>(1, 7) << 1.0, convexHullBendingEnergy / 100.0, ar, cr, bendingEnergy / 10000.0, , perimeter / 10000.0);
ref = (Mat_<double>(1, 5) << 1.0, ar, cr / 10.0, convexHullBendingEnergy / 100.0, numDefects / 100.0);
}
//Rotatie onafhankelijke aspect ratio
double FeatureExtractor::AspectRatio()
{
double ar = 0;
@@ -40,6 +41,8 @@ double FeatureExtractor::AspectRatio()
return ar;
}
//Oppervlakte van de minimale circle gedeeld door het oppervlakte van de bounding box
double FeatureExtractor::Circularity()
{
double radius = getMinEnclosingCircleRadius();
@@ -50,11 +53,13 @@ double FeatureExtractor::Circularity()
return cir;
}
//Rotated bounding box om het object
RotatedRect FeatureExtractor::Rectangle()
{
return rect;
}
//De radius van de minimale circle
double FeatureExtractor::getMinEnclosingCircleRadius()
{
float radius;
@@ -66,6 +71,7 @@ double FeatureExtractor::getMinEnclosingCircleRadius()
return rad;
}
//De lengte van het contour
double FeatureExtractor::getPerimeter()
{
double per = arcLength(contour, true);
@@ -73,6 +79,7 @@ double FeatureExtractor::getPerimeter()
return per;
}
//De bending energy van de contour
double FeatureExtractor::getBendingEnergy()
{
double energy = 0;
@@ -92,6 +99,7 @@ double FeatureExtractor::getBendingEnergy()
return energy;
}
//De bending energy van de convex hull
double FeatureExtractor::getConvexHullBendingEnergy() {
vector<Point> convex;
@@ -113,6 +121,7 @@ double FeatureExtractor::getConvexHullBendingEnergy() {
return energy;
}
//Bending energy support methode, zoekt naar de hoek tussen twee pixels volgens de freeman code
int FeatureExtractor::discoverNextRelativeDirection(const cv::Point &pos, const cv::Point &target)
{
for (int i = 0; i < 8; i++) {
@@ -128,6 +137,7 @@ int FeatureExtractor::discoverNextRelativeDirection(const cv::Point &pos, const
return -1;
}
//Het aantal defecten die in de convexhull zitten
double FeatureExtractor::convexDefects()
{
vector<int> hullsI(contour.size()); // Indices to contour points
@@ -138,6 +148,7 @@ double FeatureExtractor::convexDefects()
return (double)defects.size();
}
//Statische help functie om het contour te bepalen in een plaatje
void FeatureExtractor::findContour(Mat &image, vector<Point> &contour)
{
Mat canny_output;