Added the Communication Module to the repo.
@@ -0,0 +1,50 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(lfr_image_processing VERSION 0.1.0)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include_directories( ${OpenCV_INCLUDE_DIRS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Input
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Processing
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ControlModule
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Interpreter
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/IntersectionHandler
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Utils
|
||||
)
|
||||
|
||||
link_directories( ${Input_SOURCE_DIRS}
|
||||
${Processing_SOURCE_DIRS}
|
||||
${ControlModule_SOURCE_DIRS}
|
||||
${Interpreter_SOURCE_DIRS}
|
||||
${IntersectionHandler_SOURCE_DIRS}
|
||||
${Utils_SOURCE_DIRS}
|
||||
)
|
||||
|
||||
add_subdirectory(Input)
|
||||
add_subdirectory(Processing)
|
||||
add_subdirectory(ControlModule)
|
||||
add_subdirectory(Interpreter)
|
||||
add_subdirectory(IntersectionHandler)
|
||||
add_subdirectory(Utils)
|
||||
add_subdirectory(Spielwiese)
|
||||
|
||||
target_include_directories(Input PRIVATE .)
|
||||
target_include_directories(Processing PRIVATE .)
|
||||
target_include_directories(ControlModule PRIVATE .)
|
||||
target_include_directories(Interpreter PRIVATE .)
|
||||
target_include_directories(IntersectionHandler PRIVATE .)
|
||||
target_include_directories(Utils PRIVATE .)
|
||||
|
||||
add_executable(lfr_image_processing lfr.cpp autonomous_mode_main.cpp)
|
||||
|
||||
target_link_libraries( lfr_image_processing ${OpenCV_LIBS} Input Processing ControlModule Interpreter IntersectionHandler Utils Threads::Threads)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,12 @@
|
||||
include_directories( ${Utils_SOURCE_DIRS})
|
||||
link_directories(${Utils_SOURCE_DIRS})
|
||||
|
||||
add_library(ControlModule control_module.cpp)
|
||||
set_target_properties(ControlModule PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(ControlModule PRIVATE .)
|
||||
|
||||
target_link_libraries( ControlModule Utils)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "control_module.h"
|
||||
|
||||
ControlModule::ControlModule(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
ControlModule::~ControlModule()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class ControlModule
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
ControlModule(/* args */);
|
||||
|
||||
~ControlModule();
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
find_package( OpenCV REQUIRED )
|
||||
include_directories( ${OpenCV_INCLUDE_DIRS} ${Utils_SOURCE_DIRS})
|
||||
|
||||
link_directories(${Utils_SOURCE_DIRS})
|
||||
|
||||
add_library(Input input.cpp)
|
||||
set_target_properties(Input PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(Input PRIVATE .)
|
||||
|
||||
target_link_libraries( Input ${OpenCV_LIBS} Utils)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "input.h"
|
||||
|
||||
Input::Input(int videoHeight, int videoWidth) : cap(0), videoHeight(videoHeight), videoWidth(videoWidth)
|
||||
{
|
||||
this->cap.set(CAP_PROP_FRAME_HEIGHT, videoHeight);
|
||||
this->cap.set(CAP_PROP_FRAME_WIDTH, videoWidth);
|
||||
}
|
||||
|
||||
Input::~Input()
|
||||
{
|
||||
this->freeWebcam();
|
||||
}
|
||||
|
||||
Mat Input::readFile(String filePath)
|
||||
{
|
||||
std::srand(std::time(0));
|
||||
// Read all .jpg files from the specified folder
|
||||
std::string folder = filePath;
|
||||
std::vector<std::string> filenames;
|
||||
cv::glob(folder, filenames);
|
||||
|
||||
// Random shuffle
|
||||
std::random_shuffle(filenames.begin(), filenames.end());
|
||||
|
||||
Mat image = imread(filenames[0], IMREAD_COLOR);
|
||||
|
||||
if(image.empty())
|
||||
{
|
||||
std::cout << "Could not read the image: " << filePath << std::endl;
|
||||
return Mat();
|
||||
//To do:Exception handeling
|
||||
}
|
||||
resize(image, image, Size(this->videoWidth, this->videoHeight));
|
||||
return image;
|
||||
}
|
||||
|
||||
Mat Input::readWebcam()
|
||||
{
|
||||
Mat image;
|
||||
|
||||
if(!cap.isOpened()) {
|
||||
cout << "Fehler";
|
||||
return Mat();
|
||||
}
|
||||
|
||||
cap.read(image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void Input::freeWebcam()
|
||||
{
|
||||
this->cap.release();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
VideoCapture cap;
|
||||
|
||||
public:
|
||||
int videoHeight;
|
||||
int videoWidth;
|
||||
Input(int videoHeight, int videoWidth);
|
||||
Input() = delete;
|
||||
~Input();
|
||||
Mat readFile(String filePath);
|
||||
Mat readWebcam();
|
||||
void freeWebcam();
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
include_directories( ${Utils_SOURCE_DIRS})
|
||||
link_directories(${Utils_SOURCE_DIRS})
|
||||
|
||||
add_library(Interpreter interpreter.cpp)
|
||||
set_target_properties(Interpreter PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(Interpreter PRIVATE .)
|
||||
|
||||
target_link_libraries( Interpreter Utils)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "interpreter.h"
|
||||
|
||||
Interpreter::Interpreter(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
Interpreter::~Interpreter()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Interpreter
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
Interpreter(/* args */);
|
||||
|
||||
~Interpreter();
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
include_directories( ${Utils_SOURCE_DIRS})
|
||||
link_directories(${Utils_SOURCE_DIRS})
|
||||
|
||||
add_library(IntersectionHandler intersection_handler.cpp)
|
||||
set_target_properties(IntersectionHandler PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(IntersectionHandler PRIVATE .)
|
||||
|
||||
target_link_libraries( IntersectionHandler Utils)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "intersection_handler.h"
|
||||
|
||||
IntersectionHandler::IntersectionHandler(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
IntersectionHandler::~IntersectionHandler()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class IntersectionHandler
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
IntersectionHandler(/* args */);
|
||||
|
||||
~IntersectionHandler();
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
find_package( OpenCV REQUIRED )
|
||||
include_directories( ${OpenCV_INCLUDE_DIRS} )
|
||||
include_directories( ${Utils_SOURCE_DIRS})
|
||||
|
||||
link_directories(${Utils_SOURCE_DIRS})
|
||||
|
||||
add_library(Processing processing.cpp)
|
||||
set_target_properties(Processing PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
target_include_directories(Processing PRIVATE .)
|
||||
|
||||
target_link_libraries( Processing ${OpenCV_LIBS} Utils)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "processing.h"
|
||||
|
||||
Processing::Processing(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
Processing::~Processing()
|
||||
{
|
||||
}
|
||||
|
||||
static double angle( Point pt1, Point pt2, Point pt0 )
|
||||
{
|
||||
double dx1 = pt1.x - pt0.x;
|
||||
double dy1 = pt1.y - pt0.y;
|
||||
double dx2 = pt2.x - pt0.x;
|
||||
double dy2 = pt2.y - pt0.y;
|
||||
return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
|
||||
}
|
||||
|
||||
void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
|
||||
{
|
||||
//Idea here is: Processing module consists of two methods:
|
||||
// One (this) to do all kinds of stuff to the picture (grayscale conversion, threshold, gauss etc etc)
|
||||
// And one (the other one) to segment the lines.
|
||||
// No return value here as the input is passed by reference -> directly modified.
|
||||
cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY);
|
||||
threshold(inputPicture, inputPicture, thresholdBinary, 255, THRESH_BINARY);
|
||||
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
|
||||
Canny(inputPicture, inputPicture, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
|
||||
}
|
||||
|
||||
std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)
|
||||
{
|
||||
//See following link
|
||||
//https://stackoverflow.com/questions/45322630/how-to-detect-lines-in-opencv
|
||||
vector<Vec4i> lines;
|
||||
VectorOfLines linesInVectors;
|
||||
HoughLinesP(inputPicture, lines, 1, CV_PI/360, 150, 0, 250);
|
||||
//lines = linesInVectors.findMiddleLine(lines);
|
||||
|
||||
return lines;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <utils.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class Processing
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
Processing(/* args */);
|
||||
// To do:
|
||||
// Binärbild
|
||||
// Linien finden (HoughLinesP())
|
||||
// Entscheidung über wie viele Linien und welche Art von Linien erkannt werden (abknickende Linien)
|
||||
// End und Anfangspunkt analysieren und Winkel und Ausrichtung der Linie extrahieren (Abstand des untersten Punktes von der Mitte)
|
||||
~Processing();
|
||||
|
||||
void processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
|
||||
|
||||
std::vector<Vec4i> calculateLineSegments(const Mat& inputPicture);
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include_directories( ${OpenCV_INCLUDE_DIRS}
|
||||
${Input_SOURCE_DIRS}
|
||||
${Processing_SOURCE_DIRS}
|
||||
${ControlModule_SOURCE_DIRS}
|
||||
${Interpreter_SOURCE_DIRS}
|
||||
${IntersectionHandler_SOURCE_DIRS}
|
||||
${Utils_SOURCE_DIRS}
|
||||
)
|
||||
|
||||
link_directories( ${Input_SOURCE_DIRS}
|
||||
${Processing_SOURCE_DIRS}
|
||||
${ControlModule_SOURCE_DIRS}
|
||||
${Interpreter_SOURCE_DIRS}
|
||||
${IntersectionHandler_SOURCE_DIRS}
|
||||
${Utils_SOURCE_DIRS}
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(Input PRIVATE .)
|
||||
target_include_directories(Processing PRIVATE .)
|
||||
target_include_directories(ControlModule PRIVATE .)
|
||||
target_include_directories(Interpreter PRIVATE .)
|
||||
target_include_directories(IntersectionHandler PRIVATE .)
|
||||
target_include_directories(Utils PRIVATE .)
|
||||
|
||||
add_executable(spielwiese spielwiese.cpp)
|
||||
|
||||
target_link_libraries( spielwiese ${OpenCV_LIBS} Input Processing ControlModule Interpreter IntersectionHandler Utils Threads::Threads)
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <input.h>
|
||||
#include <processing.h>
|
||||
#include <control_module.h>
|
||||
#include <interpreter.h>
|
||||
#include <intersection_handler.h>
|
||||
|
||||
void sweep_em_all(int thresholdBinary, int videoHeight, int videoWidth, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
|
||||
{
|
||||
Input input(videoHeight, videoWidth);
|
||||
Processing processing;
|
||||
|
||||
namedWindow("Display window");
|
||||
while(true)
|
||||
{
|
||||
Mat image = input.readFile("C:\\Users\\User\\Desktop\\Studium\\02_Master_MSY\\2. Semester Winter 22 23\\Projekt\\Line-Following-Robot\\Test_data");
|
||||
Mat processedImage = image;
|
||||
processing.processImage(processedImage, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2 ,apertureSizeCanny);
|
||||
std::vector<Vec4i> lines = processing.calculateLineSegments(processedImage);
|
||||
for( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
line( image, Point(lines[i][0], lines[i][1]),
|
||||
Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
|
||||
}
|
||||
imshow("Display window", image);
|
||||
char c = (char)waitKey(1);
|
||||
}
|
||||
destroyWindow("Display window");
|
||||
}
|
||||
|
||||
void in_depth_processing_chain(int thresholdBinary, int videoHeight, int videoWidth, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
|
||||
{
|
||||
std::string outputFolder = "C:\\Users\\User\\Desktop\\temp";
|
||||
Input input(videoHeight, videoWidth);
|
||||
|
||||
Mat image = input.readFile("C:\\Users\\User\\Desktop\\Studium\\02_Master_MSY\\2. Semester Winter 22 23\\Projekt\\Line-Following-Robot\\Test_data");
|
||||
imwrite(outputFolder + "\\01_input.jpg", image);
|
||||
cvtColor(image, image, COLOR_BGR2GRAY);
|
||||
imwrite(outputFolder + "\\02_color_convert.jpg", image);
|
||||
GaussianBlur(image, image, Size(gaussKernelSize, gaussKernelSize), 0);
|
||||
imwrite(outputFolder + "\\03_gauss.jpg", image);
|
||||
threshold(image, image, thresholdBinary, 255, THRESH_BINARY);
|
||||
imwrite(outputFolder + "\\04_threshold.jpg", image);
|
||||
Canny(image, image, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
|
||||
imwrite(outputFolder + "\\05_canny.jpg", image);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//Disable opencv logging messages
|
||||
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
|
||||
|
||||
const int thresholdBinary = 140;
|
||||
const int videoHeight = 720;
|
||||
const int videoWidth = 960;
|
||||
const int gaussKernelSize = 11;
|
||||
const int thresholdCanny1 = 50;
|
||||
const int thresholdCanny2 = 100;
|
||||
const int apertureSizeCanny = 3;
|
||||
|
||||
//sweep_em_all(thresholdBinary, videoHeight, videoWidth, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
|
||||
in_depth_processing_chain(thresholdBinary, videoHeight, videoWidth, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
|
||||
}
|
||||
|
After Width: | Height: | Size: 253 KiB |
|
After Width: | Height: | Size: 301 KiB |
|
After Width: | Height: | Size: 268 KiB |
|
After Width: | Height: | Size: 296 KiB |
|
After Width: | Height: | Size: 311 KiB |
|
After Width: | Height: | Size: 254 KiB |
|
After Width: | Height: | Size: 252 KiB |
|
After Width: | Height: | Size: 265 KiB |
|
After Width: | Height: | Size: 245 KiB |
|
After Width: | Height: | Size: 327 KiB |
|
After Width: | Height: | Size: 282 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 328 KiB |
|
After Width: | Height: | Size: 276 KiB |
|
After Width: | Height: | Size: 310 KiB |
|
After Width: | Height: | Size: 299 KiB |
|
After Width: | Height: | Size: 248 KiB |
|
After Width: | Height: | Size: 328 KiB |
|
After Width: | Height: | Size: 316 KiB |
|
After Width: | Height: | Size: 329 KiB |
|
After Width: | Height: | Size: 295 KiB |
|
After Width: | Height: | Size: 279 KiB |
|
After Width: | Height: | Size: 266 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 269 KiB |
|
After Width: | Height: | Size: 277 KiB |
|
After Width: | Height: | Size: 262 KiB |
|
After Width: | Height: | Size: 249 KiB |
@@ -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);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "lfr.h"
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//Disable opencv logging messages
|
||||
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
|
||||
|
||||
const int thresholdBinary = 140;
|
||||
const int videoHeight = 240;
|
||||
const int videoWidth = 320;
|
||||
const int gaussKernelSize = 21;
|
||||
const int thresholdCanny1 = 50;
|
||||
const int thresholdCanny2 = 100;
|
||||
const int apertureSizeCanny = 3;
|
||||
|
||||
LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
|
||||
lfr.startLoop();
|
||||
//To end the video stream, write any char in the console.
|
||||
char a;
|
||||
std::cin >> a;
|
||||
lfr.endLoop();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "lfr.h"
|
||||
|
||||
|
||||
LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
|
||||
: iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler()
|
||||
{
|
||||
this->iAmLooping = false;
|
||||
this->thresholdBinary = thresholdBinary;
|
||||
this->gaussKernelSize = gaussKernelSize;
|
||||
this->thresholdCanny1 = thresholdCanny1;
|
||||
this->thresholdCanny2 = thresholdCanny2;
|
||||
this->apertureSizeCanny = apertureSizeCanny;
|
||||
}
|
||||
|
||||
LFR::~LFR()
|
||||
{
|
||||
if(iAmLooping)
|
||||
{
|
||||
this->endLoop();
|
||||
}
|
||||
}
|
||||
|
||||
void LFR::loop()
|
||||
{
|
||||
namedWindow("Display window");
|
||||
while(iAmLooping)
|
||||
{
|
||||
Mat image = input.readWebcam();
|
||||
processing.processImage(image, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
|
||||
std::vector<Vec4i> lines = processing.calculateLineSegments(image);
|
||||
for( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
line( image, Point(lines[i][0], lines[i][1]),
|
||||
Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
|
||||
}
|
||||
imshow("Display window", image);
|
||||
char c = (char)waitKey(1);
|
||||
}
|
||||
destroyWindow("Display window");
|
||||
input.freeWebcam();
|
||||
}
|
||||
|
||||
void LFR::startLoop()
|
||||
{
|
||||
iAmLooping = true;
|
||||
this->loopThread=thread(&LFR::loop, this);
|
||||
}
|
||||
|
||||
void LFR::endLoop()
|
||||
{
|
||||
iAmLooping = false;
|
||||
this->loopThread.join();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <future>
|
||||
#include <thread>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include <input.h>
|
||||
#include <processing.h>
|
||||
#include <control_module.h>
|
||||
#include <interpreter.h>
|
||||
#include <intersection_handler.h>
|
||||
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class LFR
|
||||
{
|
||||
Input input;
|
||||
Processing processing;
|
||||
ControlModule controlModule;
|
||||
Interpreter interpreter;
|
||||
IntersectionHandler intersectionHandler;
|
||||
volatile bool iAmLooping;
|
||||
void loop();
|
||||
thread loopThread;
|
||||
int thresholdBinary;
|
||||
int gaussKernelSize;
|
||||
int thresholdCanny1;
|
||||
int thresholdCanny2;
|
||||
int apertureSizeCanny;
|
||||
|
||||
public:
|
||||
|
||||
LFR() = delete;
|
||||
LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
|
||||
~LFR();
|
||||
|
||||
void startLoop();
|
||||
void endLoop();
|
||||
|
||||
};
|
||||