{
}
-void BlobDetector::detect(const cv::Mat& image, vector<cv::KeyPoint>& keypoints, const cv::Mat& mask) const
+void BlobDetector::detect(const cv::Mat& image, vector<cv::Point2f>& keypoints, const cv::Mat& mask) const
{
detectImpl(image, keypoints, mask);
}
//waitKey();
}
-void BlobDetector::detectImpl(const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints, const cv::Mat& mask) const
+void BlobDetector::detectImpl(const cv::Mat& image, std::vector<cv::Point2f>& keypoints, const cv::Mat& mask) const
{
keypoints.clear();
Mat grayscaleImage;
normalizer += centers[i][j].confidence;
}
sumPoint *= (1. / normalizer);
- KeyPoint kpt(sumPoint, params.defaultKeypointSize);
- keypoints.push_back(kpt);
+ keypoints.push_back(sumPoint);
}
}
#define BLOBDETECTOR_HPP_
#include "precomp.hpp"
-#include "../../features2d/include/opencv2/features2d/features2d.hpp"
struct BlobDetectorParameters
{
{
public:
BlobDetector(const BlobDetectorParameters ¶meters = BlobDetectorParameters());
- void detect(const cv::Mat& image, vector<cv::KeyPoint>& keypoints, const cv::Mat& mask = cv::Mat()) const;
+ void detect(const cv::Mat& image, std::vector<cv::Point2f>& keypoints, const cv::Mat& mask = cv::Mat()) const;
protected:
struct Center
{
double confidence;
};
- virtual void detectImpl(const cv::Mat& image, vector<cv::KeyPoint>& keypoints, const cv::Mat& mask = cv::Mat()) const;
- virtual void findBlobs(const cv::Mat &image, const cv::Mat &binaryImage, vector<Center> ¢ers) const;
+ virtual void detectImpl(const cv::Mat& image, std::vector<cv::Point2f>& keypoints, const cv::Mat& mask = cv::Mat()) const;
+ virtual void findBlobs(const cv::Mat &image, const cv::Mat &binaryImage, std::vector<Center> ¢ers) const;
- cv::Point2d computeGrayscaleCentroid(const cv::Mat &image, const vector<cv::Point> &contour) const;
+ cv::Point2d computeGrayscaleCentroid(const cv::Mat &image, const std::vector<cv::Point> &contour) const;
BlobDetectorParameters params;
};
{
Ptr<BlobDetector> detector = new BlobDetector();
//Ptr<FeatureDetector> detector = new MserFeatureDetector();
- vector<KeyPoint> keypoints;
+ vector<Point2f> keypoints;
detector->detect(image, keypoints);
CirclesGridFinderParameters parameters;
#include "circlesgrid.hpp"
using namespace cv;
+using namespace std;
Graph::Graph(int n)
{
existingVertexGain = 0;
}
-CirclesGridFinder::CirclesGridFinder(Size _patternSize, const vector<KeyPoint> &testKeypoints,
+CirclesGridFinder::CirclesGridFinder(Size _patternSize, const vector<Point2f> &testKeypoints,
const CirclesGridFinderParameters &_parameters) :
patternSize(_patternSize)
{
}
Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const vector<Point2f>& centers,
- const vector<KeyPoint> &keypoints, vector<KeyPoint> &warpedKeypoints)
+ const vector<Point2f> &keypoints, vector<Point2f> &warpedKeypoints)
{
assert( !centers.empty() );
const float edgeLength = 30;
vector<Point2f> srcKeypoints;
for (size_t i = 0; i < keypoints.size(); i++)
{
- srcKeypoints.push_back(keypoints[i].pt);
+ srcKeypoints.push_back(keypoints[i]);
}
Mat dstKeypointsMat;
for (size_t i = 0; i < dstKeypoints.size(); i++)
{
Point2f pt = dstKeypoints[i];
- warpedKeypoints.push_back(KeyPoint(pt, keypointScale));
+ warpedKeypoints.push_back(pt);
}
return H;
float minDist = std::numeric_limits<float>::max();
for (size_t i = 0; i < keypoints.size(); i++)
{
- float dist = norm(pt - keypoints[i].pt);
+ float dist = norm(pt - keypoints[i]);
if (dist < minDist)
{
minDist = dist;
void CirclesGridFinder::addPoint(Point2f pt, vector<int> &points)
{
int ptIdx = findNearestKeypoint(pt);
- if (norm(keypoints[ptIdx].pt - pt) > parameters.minDistanceToAddKeypoint)
+ if (norm(keypoints[ptIdx] - pt) > parameters.minDistanceToAddKeypoint)
{
- KeyPoint kpt = KeyPoint(pt, parameters.keypointScale);
+ Point2f kpt = Point2f(pt);
keypoints.push_back(kpt);
points.push_back(keypoints.size() - 1);
}
{
for (size_t i = 0; i < holes[seedLineIdx].size(); i++)
{
- Point2f pt = keypoints[holes[seedLineIdx][i]].pt + basisVec;
+ Point2f pt = keypoints[holes[seedLineIdx][i]] + basisVec;
addPoint(pt, line);
seeds.push_back(holes[seedLineIdx][i]);
}
{
for (size_t i = 0; i < holes.size(); i++)
{
- Point2f pt = keypoints[holes[i][seedLineIdx]].pt + basisVec;
+ Point2f pt = keypoints[holes[i][seedLineIdx]] + basisVec;
addPoint(pt, line);
seeds.push_back(holes[i][seedLineIdx]);
}
if (i == j)
continue;
- Point2f vec = keypoints[i].pt - keypoints[j].pt;
+ Point2f vec = keypoints[i] - keypoints[j];
for (size_t k = 0; k < hulls.size(); k++)
{
if (i == j)
continue;
- Point2f vec = keypoints[i].pt - keypoints[j].pt;
+ Point2f vec = keypoints[i] - keypoints[j];
float dist = norm(vec);
bool isNeighbors = true;
if (k == i || k == j)
continue;
- float dist1 = norm(keypoints[i].pt - keypoints[k].pt);
- float dist2 = norm(keypoints[j].pt - keypoints[k].pt);
+ float dist1 = norm(keypoints[i] - keypoints[k]);
+ float dist2 = norm(keypoints[j] - keypoints[k]);
if (dist1 < dist && dist2 < dist)
{
isNeighbors = false;
if (isNeighbors)
{
- vectors.push_back(keypoints[i].pt - keypoints[j].pt);
+ vectors.push_back(keypoints[i] - keypoints[j]);
if (drawImage != 0)
{
- line(*drawImage, keypoints[i].pt, keypoints[j].pt, Scalar(255, 0, 0), 2);
- circle(*drawImage, keypoints[i].pt, 3, Scalar(0, 0, 255), -1);
- circle(*drawImage, keypoints[j].pt, 3, Scalar(0, 0, 255), -1);
+ line(*drawImage, keypoints[i], keypoints[j], Scalar(255, 0, 0), 2);
+ circle(*drawImage, keypoints[i], 3, Scalar(0, 0, 255), -1);
+ circle(*drawImage, keypoints[j], 3, Scalar(0, 0, 255), -1);
}
}
}
//int bestPathIdx = rand() % longestPaths.size();
bestPath = longestPaths.at(bestPathIdx);
- bool needReverse = (bestGraphIdx == 0 && keypoints[bestPath.lastVertex].pt.x < keypoints[bestPath.firstVertex].pt.x)
- || (bestGraphIdx == 1 && keypoints[bestPath.lastVertex].pt.y < keypoints[bestPath.firstVertex].pt.y);
+ bool needReverse = (bestGraphIdx == 0 && keypoints[bestPath.lastVertex].x < keypoints[bestPath.firstVertex].x)
+ || (bestGraphIdx == 1 && keypoints[bestPath.lastVertex].y < keypoints[bestPath.firstVertex].y);
if (needReverse)
{
std::swap(bestPath.lastVertex, bestPath.firstVertex);
{
if (basisGraphs[i].areVerticesAdjacent(v1, v2))
{
- line(drawImage, keypoints[v1].pt, keypoints[v2].pt, edgeColor, edgeThickness);
+ line(drawImage, keypoints[v1], keypoints[v2], edgeColor, edgeThickness);
}
}
}
{
for (size_t v = 0; v < basisGraphs[0].getVerticesCount(); v++)
{
- circle(drawImage, keypoints[v].pt, vertexRadius, vertexColor, vertexThickness);
+ circle(drawImage, keypoints[v], vertexRadius, vertexColor, vertexThickness);
}
}
}
for (size_t j = 0; j < holes[i].size(); j++)
{
if (j != holes[i].size() - 1)
- line(drawImage, keypoints[holes[i][j]].pt, keypoints[holes[i][j + 1]].pt, Scalar(255, 0, 0), 2);
+ line(drawImage, keypoints[holes[i][j]], keypoints[holes[i][j + 1]], Scalar(255, 0, 0), 2);
if (i != holes.size() - 1)
- line(drawImage, keypoints[holes[i][j]].pt, keypoints[holes[i + 1][j]].pt, Scalar(255, 0, 0), 2);
+ line(drawImage, keypoints[holes[i][j]], keypoints[holes[i + 1][j]], Scalar(255, 0, 0), 2);
- //circle(drawImage, keypoints[holes[i][j]].pt, holeRadius, holeColor, holeThickness);
- circle(drawImage, keypoints[holes[i][j]].pt, holeRadius, holeColor, holeThickness);
+ //circle(drawImage, keypoints[holes[i][j]], holeRadius, holeColor, holeThickness);
+ circle(drawImage, keypoints[holes[i][j]], holeRadius, holeColor, holeThickness);
}
}
}
{
for (size_t j = 0; j < holes[i].size(); j++)
{
- outHoles.push_back(keypoints[holes[i][j]].pt);
+ outHoles.push_back(keypoints[holes[i][j]]);
}
}
}
#include <set>
#include "precomp.hpp"
-#include "../../features2d/include/opencv2/features2d/features2d.hpp"
class Graph
{
public:
- typedef set<int> Neighbors;
+ typedef std::set<int> Neighbors;
struct Vertex
{
Neighbors neighbors;
};
- typedef map<int, Vertex> Vertices;
+ typedef std::map<int, Vertex> Vertices;
Graph( int n);
bool doesVertexExist( int id ) const;
int lastVertex;
int length;
- vector<int> vertices;
+ std::vector<int> vertices;
Path(int first = -1, int last = -1, int len = -1)
{
class CirclesGridFinder
{
public:
- CirclesGridFinder(cv::Size patternSize, const vector<cv::KeyPoint> &testKeypoints,
+ CirclesGridFinder(cv::Size patternSize, const std::vector<cv::Point2f> &testKeypoints,
const CirclesGridFinderParameters ¶meters = CirclesGridFinderParameters());
bool findHoles();
- static cv::Mat rectifyGrid(cv::Size detectedGridSize, const vector<cv::Point2f>& centers,
- const vector<cv::KeyPoint> &keypoint, vector<cv::KeyPoint> &warpedKeypoints);
+ static cv::Mat rectifyGrid(cv::Size detectedGridSize, const std::vector<cv::Point2f>& centers,
+ const std::vector<cv::Point2f> &keypoint, std::vector<cv::Point2f> &warpedKeypoints);
- void getHoles(vector<cv::Point2f> &holes) const;
+ void getHoles(std::vector<cv::Point2f> &holes) const;
cv::Size getDetectedGridSize() const;
- void drawBasis(const vector<cv::Point2f> &basis, cv::Point2f origin, cv::Mat &drawImg) const;
- void drawBasisGraphs(const vector<Graph> &basisGraphs, cv::Mat &drawImg, bool drawEdges = true, bool drawVertices =
+ void drawBasis(const std::vector<cv::Point2f> &basis, cv::Point2f origin, cv::Mat &drawImg) const;
+ void drawBasisGraphs(const std::vector<Graph> &basisGraphs, cv::Mat &drawImg, bool drawEdges = true, bool drawVertices =
true) const;
void drawHoles(const cv::Mat &srcImage, cv::Mat &drawImage) const;
private:
- void computeEdgeVectorsOfRNG(vector<cv::Point2f> &vectors, cv::Mat *drawImage = 0) const;
- void filterOutliersByDensity(const vector<cv::Point2f> &samples, vector<cv::Point2f> &filteredSamples);
- void findBasis(const vector<cv::Point2f> &samples, vector<cv::Point2f> &basis, vector<Graph> &basisGraphs);
- void findMCS(const vector<cv::Point2f> &basis, vector<Graph> &basisGraphs);
- size_t findLongestPath(vector<Graph> &basisGraphs, Path &bestPath);
- float computeGraphConfidence(const vector<Graph> &basisGraphs, bool addRow, const vector<int> &points, const vector<
+ void computeEdgeVectorsOfRNG(std::vector<cv::Point2f> &vectors, cv::Mat *drawImage = 0) const;
+ void filterOutliersByDensity(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &filteredSamples);
+ void findBasis(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &basis, std::vector<Graph> &basisGraphs);
+ void findMCS(const std::vector<cv::Point2f> &basis, std::vector<Graph> &basisGraphs);
+ size_t findLongestPath(std::vector<Graph> &basisGraphs, Path &bestPath);
+ float computeGraphConfidence(const std::vector<Graph> &basisGraphs, bool addRow, const std::vector<int> &points, const std::vector<
int> &seeds);
- void addHolesByGraph(const vector<Graph> &basisGraphs, bool addRow, cv::Point2f basisVec);
+ void addHolesByGraph(const std::vector<Graph> &basisGraphs, bool addRow, cv::Point2f basisVec);
int findNearestKeypoint(cv::Point2f pt) const;
- void addPoint(cv::Point2f pt, vector<int> &points);
- void findCandidateLine(vector<int> &line, int seedLineIdx, bool addRow, cv::Point2f basisVec, vector<int> &seeds);
- void findCandidateHoles(vector<int> &above, vector<int> &below, bool addRow, cv::Point2f basisVec,
- vector<int> &aboveSeeds, vector<int> &belowSeeds);
- static bool areCentersNew( const vector<int> &newCenters, const vector<vector<int> > &holes );
+ void addPoint(cv::Point2f pt, std::vector<int> &points);
+ void findCandidateLine(std::vector<int> &line, int seedLineIdx, bool addRow, cv::Point2f basisVec, std::vector<int> &seeds);
+ void findCandidateHoles(std::vector<int> &above, std::vector<int> &below, bool addRow, cv::Point2f basisVec,
+ std::vector<int> &aboveSeeds, std::vector<int> &belowSeeds);
+ static bool areCentersNew( const std::vector<int> &newCenters, const std::vector<std::vector<int> > &holes );
bool isDetectionCorrect();
static void insertWinner(float aboveConfidence, float belowConfidence, float minConfidence,
bool addRow,
- const vector<int> &above, const vector<int> &below, vector<vector<int> > &holes);
+ const std::vector<int> &above, const std::vector<int> &below, std::vector<std::vector<int> > &holes);
static bool areVerticesAdjacent(const Graph &graph, int vertex1, int vertex2);
- vector<cv::KeyPoint> keypoints;
+ std::vector<cv::Point2f> keypoints;
- vector<vector<int> > holes;
+ std::vector<std::vector<int> > holes;
const cv::Size patternSize;
CirclesGridFinderParameters parameters;
};