Werkt nog steeds niet

This commit is contained in:
2017-11-22 16:36:07 +01:00
parent f59e576758
commit acff1c02b1
2 changed files with 68 additions and 37 deletions
@@ -23,56 +23,69 @@ struct pointCompare
int allContours(Mat binaryImage, vector<vector<Point>>& contourVecVec)
{
Mat labeledImage;
vector<Point2d *> firstPixelVec2;
vector<Point2d *> posVec2;
vector<int> areaVec2;
int numberOfBlobs = labelBLOBsInfo(binaryImage, labeledImage, firstPixelVec2, posVec2, areaVec2);
Point b0, b1, c0, c1, firstb0, firstb1;
for (Point2d *ptr : firstPixelVec2) {
vector<Point> contourVec;
for (int y = 0; y < binaryImage.rows; y++) {
for (int x = 0; x < binaryImage.cols; x++)
{
Point p = Point(x, y);
firstb0 = Point((int)ptr->y, (int)ptr->x);
b0 = Point((int)ptr->y, (int)ptr->x);
c0 = Point((int)(ptr->y - 1), (int)ptr->x);
int firstDirection = discoverNext(binaryImage, b0, 6);
b1 = getDirPos(b0, firstDirection);
firstb1 = getDirPos(b0, firstDirection);
c1 = getDirPos(b0, (firstDirection + 7) % 8);
contourVec.push_back(b0);
contourVec.push_back(b1);
do {
b0 = b1;
c0 = c1;
int dir = discoverNext(binaryImage, b0, discoverNextRelativeDirection(b0, c0));
if (dir < 0)
if (getEntryImage(binaryImage, y, x) != 1)
{
cout << "Het gaat eventjes niet goed hoor: " << b0 << " - " << c0 << endl;
continue;
}
b1 = getDirPos(b0, dir);
c1 = getDirPos(b0, (dir + 7) % 8);
if (isInsideContours(contourVecVec, p))
{
continue;
}
if(!contains(contourVec, b1))
contourVec.push_back(b1);
} while (b0 != firstb0 && b1 != firstb1);
vector<Point> contourVec;
contourVecVec.push_back(contourVec);
firstb0 = p;
b0 = p;
c0 = Point(x - 1, y);
int firstDirection = discoverNext(binaryImage, b0, discoverNextRelativeDirection(b0, c0));
b1 = getDirPos(b0, firstDirection);
firstb1 = getDirPos(b0, firstDirection);
c1 = getDirPos(b0, (firstDirection + 7) % 8);
contourVec.push_back(b0);
contourVec.push_back(b1);
do {
b0 = b1;
c0 = c1;
int cdir = discoverNextRelativeDirection(b0, c0);
int dir = discoverNext(binaryImage, b0, cdir);
if (dir < 0)
{
cout << "Het gaat eventjes niet goed hoor: " << cdir << " : " << b0 << " - " << c0 << endl;
}
b1 = getDirPos(b0, dir);
c1 = getDirPos(b0, (dir + 7) % 8);
//TODO
if (!contains(contourVec, b1))
contourVec.push_back(b1);
} while (b0 != firstb0 && b1 != firstb1);
if(contourVec.size() > 5)
contourVecVec.push_back(contourVec);
}
}
flip(contourVecVec);
return numberOfBlobs; //number of objects
return contourVecVec.size(); //number of objects
}
int discoverNext(Mat &binaryImage, cv::Point pos, int beginDirection)
@@ -143,4 +156,19 @@ void flip(vector<vector<Point>> &vec)
p.y = x;
}
}
}
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;
}
@@ -1,9 +1,11 @@
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv/cv.h>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
@@ -26,4 +28,5 @@ int discoverNextRelativeDirection(cv::Point pos, cv::Point target);
cv::Point getDirPos(cv::Point pos, int dir);
bool contains(vector<Point> vec, Point p);
void flip(vector<vector<Point>> &vec);
void flip(vector<vector<Point>> &vec);
bool isInsideContours(vector<vector<Point>>& vec, Point point);