Added the Communication Module to the repo.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
find_package( OpenCV REQUIRED )
|
||||
include_directories( ${OpenCV_INCLUDE_DIRS} )
|
||||
|
||||
add_library(Utils utils.cpp)
|
||||
set_target_properties(Utils PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(Utils PRIVATE .)
|
||||
|
||||
target_link_libraries( Utils ${OpenCV_LIBS} )
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "utils.h"
|
||||
|
||||
LFRPoint::LFRPoint(/* args */) : x(0.0), y(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
LFRPoint::LFRPoint(double x, double y): x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
LFRPoint::~LFRPoint()
|
||||
{
|
||||
}
|
||||
|
||||
LFRVector::LFRVector(/* args */) : LFRPoint()
|
||||
{
|
||||
}
|
||||
|
||||
LFRVector::LFRVector(double x, double y) : LFRPoint(x, y)
|
||||
{
|
||||
}
|
||||
|
||||
LFRVector::LFRVector(const LFRPoint& pt) : LFRPoint(pt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LFRVector::~LFRVector()
|
||||
{
|
||||
}
|
||||
|
||||
LFRLine::LFRLine(/* args */) : start(), dir()
|
||||
{
|
||||
}
|
||||
|
||||
LFRLine::LFRLine(LFRPoint start, LFRVector dir) : start(start), dir(dir)
|
||||
{
|
||||
}
|
||||
|
||||
LFRLine::LFRLine(LFRPoint start, LFRPoint end) : start(start)
|
||||
{
|
||||
dir = end - start;
|
||||
}
|
||||
|
||||
LFRLine::~LFRLine()
|
||||
{
|
||||
}
|
||||
|
||||
VectorOfLines::VectorOfLines()
|
||||
{
|
||||
}
|
||||
|
||||
VectorOfLines::~VectorOfLines()
|
||||
{
|
||||
}
|
||||
|
||||
double VectorOfLines::calcGradient(Point p0, Point p1)
|
||||
{
|
||||
double gradient = (p1.y - p0.y)/(p1.x - p0.x + 1e-10);
|
||||
return p1.x > p0.x ? gradient : - gradient;
|
||||
}
|
||||
|
||||
float VectorOfLines::calcZeroPoint(cv::Point x, float m)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double VectorOfLines::calcDistance(Point p0, Point p1)
|
||||
{
|
||||
return sqrt(pow(p1.y - p0.y, 2) + pow(p1.x - p0.x, 2));
|
||||
}
|
||||
|
||||
vector<Vec4i> VectorOfLines::findMiddleLine(vector<Vec4i> &lines){
|
||||
Point point11;
|
||||
Point point12;
|
||||
Point point21;
|
||||
Point point22;
|
||||
vector<Vec4i> middleLines;
|
||||
for( size_t i = 0; i < (lines.size() - 1); i++ )
|
||||
{
|
||||
point11 = Point(lines[i][0], lines[i][1]);
|
||||
point12 = Point( lines[i][2], lines[i][3]);
|
||||
double gradient1 = VectorOfLines::calcGradient(point11, point12);
|
||||
|
||||
//Compare every Line with the other
|
||||
for( size_t j = 0; j < (lines.size()); j++ )
|
||||
{
|
||||
if(j != i)
|
||||
{
|
||||
point21 = Point(lines[j][0], lines[j][1]);
|
||||
point22 = Point(lines[j][2], lines[j][3]);
|
||||
double gradient2 = VectorOfLines::calcGradient(point21, point22);
|
||||
if(norm(gradient1 - gradient2) < 0.15)
|
||||
{
|
||||
middleLines.push_back(Vec4i((point11.x+point21.x)/2, (point11.y+point21.y)/2, (point12.x+point22.x)/2, (point12.y+point22.y)/2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return middleLines;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
class LFRPoint
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
double x, y;
|
||||
LFRPoint(/* args */);
|
||||
LFRPoint(double x, double y);
|
||||
~LFRPoint();
|
||||
|
||||
LFRPoint operator-(const LFRPoint& pt){return LFRPoint(x-pt.x, y-pt.y);}
|
||||
LFRPoint operator+(const LFRPoint& pt){return LFRPoint(x+pt.x, y+pt.y);}
|
||||
};
|
||||
|
||||
class LFRVector : public LFRPoint
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
LFRVector(/* args */);
|
||||
LFRVector(double x, double y);
|
||||
LFRVector(const LFRPoint& pt);
|
||||
~LFRVector();
|
||||
|
||||
};
|
||||
|
||||
class LFRLine
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
|
||||
public:
|
||||
LFRPoint start;
|
||||
LFRVector dir;
|
||||
|
||||
LFRLine(/* args */);
|
||||
LFRLine(LFRPoint start, LFRVector dir);
|
||||
LFRLine(LFRPoint start, LFRPoint end);
|
||||
~LFRLine();
|
||||
};
|
||||
|
||||
class VectorOfLines{
|
||||
private:
|
||||
public:
|
||||
Point startPoint;
|
||||
float gradient;
|
||||
float zeroPoint;
|
||||
VectorOfLines();
|
||||
~VectorOfLines();
|
||||
static double calcGradient(Point x, Point y);
|
||||
float calcZeroPoint(cv::Point x, float m);
|
||||
static double calcDistance(Point p0, Point p1);
|
||||
vector<Vec4i> findMiddleLine(vector<Vec4i> &lines);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user