Bugfixes and improved bending energy
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
// 7 0 1
|
// 7 0 1
|
||||||
// 6 X 2
|
// 6 X 2
|
||||||
// 5 4 3
|
// 5 4 3
|
||||||
int rotateX[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
|
volatile int rotateX[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
|
||||||
int rotateY[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
|
volatile int rotateY[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
|
||||||
|
|
||||||
int allContours(Mat binaryImage, vector<vector<Point>>& contourVecVec)
|
int allContours(Mat binaryImage, vector<vector<Point>>& contourVecVec)
|
||||||
{
|
{
|
||||||
@@ -41,10 +41,10 @@ int allContours(Mat binaryImage, vector<vector<Point>>& contourVecVec)
|
|||||||
|
|
||||||
int dir = discoverNext(binaryImage, b0, discoverNextRelativeDirection(b0, c0));
|
int dir = discoverNext(binaryImage, b0, discoverNextRelativeDirection(b0, c0));
|
||||||
|
|
||||||
if (dir < 0)
|
//if (dir < 0)
|
||||||
{
|
//{
|
||||||
cout << "Er is niks aan de hand! " << " : " << b0 << " - " << c0 << endl;
|
// cout << "Er is niks aan de hand! " << " : " << b0 << " - " << c0 << endl;
|
||||||
}
|
//}
|
||||||
|
|
||||||
b1 = getDirPos(b0, dir);
|
b1 = getDirPos(b0, dir);
|
||||||
c1 = getDirPos(b0, (dir + 7) % 8);
|
c1 = getDirPos(b0, (dir + 7) % 8);
|
||||||
@@ -136,28 +136,19 @@ void flip(vector<vector<Point>> &vec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInsideContours(vector<vector<Point>>& vec, Point point)
|
|
||||||
{
|
|
||||||
for (vector<Point> cont : vec)
|
|
||||||
{
|
|
||||||
int i = pointPolygonTest(cont, point, false);
|
|
||||||
|
|
||||||
if (i >= 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double getBendingEnergy(const vector<Point>& contour)
|
double getBendingEnergy(const vector<Point>& contour)
|
||||||
{
|
{
|
||||||
double energy = 0;
|
double energy = 0;
|
||||||
|
int dir = 0;
|
||||||
|
int prevdir = 0;
|
||||||
|
|
||||||
Point previousPoint = contour[contour.size() - 1];
|
Point previousPoint = contour[contour.size() - 1];
|
||||||
|
|
||||||
for (Point p : contour)
|
for (Point p : contour)
|
||||||
{
|
{
|
||||||
energy += discoverNextRelativeDirection(previousPoint, p);
|
dir = discoverNextRelativeDirection(previousPoint, p);
|
||||||
|
energy += (dir - prevdir + 8) % 8;
|
||||||
|
prevdir = dir;
|
||||||
previousPoint = p;
|
previousPoint = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
//
|
//
|
||||||
// Jan Oostindie, dd 8-11-2016
|
// Jan Oostindie, dd 8-11-2016
|
||||||
//
|
//
|
||||||
|
//#pragma GCC push_options
|
||||||
|
//#pragma GCC optimize ("O0")
|
||||||
|
|
||||||
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -117,3 +120,5 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#pragma GCC pop_options
|
||||||
Reference in New Issue
Block a user