Werkt nog steeds niet
This commit is contained in:
@@ -23,56 +23,69 @@ struct pointCompare
|
|||||||
|
|
||||||
int allContours(Mat binaryImage, vector<vector<Point>>& contourVecVec)
|
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;
|
Point b0, b1, c0, c1, firstb0, firstb1;
|
||||||
|
|
||||||
for (Point2d *ptr : firstPixelVec2) {
|
for (int y = 0; y < binaryImage.rows; y++) {
|
||||||
vector<Point> contourVec;
|
for (int x = 0; x < binaryImage.cols; x++)
|
||||||
|
{
|
||||||
|
Point p = Point(x, y);
|
||||||
|
|
||||||
firstb0 = Point((int)ptr->y, (int)ptr->x);
|
if (getEntryImage(binaryImage, y, x) != 1)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
cout << "Het gaat eventjes niet goed hoor: " << b0 << " - " << c0 << endl;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
b1 = getDirPos(b0, dir);
|
if (isInsideContours(contourVecVec, p))
|
||||||
c1 = getDirPos(b0, (dir + 7) % 8);
|
{
|
||||||
|
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);
|
flip(contourVecVec);
|
||||||
|
|
||||||
return numberOfBlobs; //number of objects
|
return contourVecVec.size(); //number of objects
|
||||||
}
|
}
|
||||||
|
|
||||||
int discoverNext(Mat &binaryImage, cv::Point pos, int beginDirection)
|
int discoverNext(Mat &binaryImage, cv::Point pos, int beginDirection)
|
||||||
@@ -144,3 +157,18 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
#include <opencv2/highgui/highgui.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
||||||
|
#include <opencv2\imgproc\imgproc.hpp>
|
||||||
#include <opencv/cv.h>
|
#include <opencv/cv.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -27,3 +29,4 @@ cv::Point getDirPos(cv::Point pos, int dir);
|
|||||||
|
|
||||||
bool contains(vector<Point> vec, Point p);
|
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);
|
||||||
Reference in New Issue
Block a user