Introduce variables for canny stuff instead of hardcoding

This commit is contained in:
Tim Zeuner 2022-11-16 11:18:56 +01:00
parent d9628550d4
commit 8611a47b75
6 changed files with 21 additions and 9 deletions

View File

@ -17,16 +17,16 @@ static double angle( Point pt1, Point pt2, Point pt0 )
return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
}
void Processing::processImage(Mat& inputPicture, int thresholdValue, int gaussKernelSize)
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, thresholdValue, 255, THRESH_BINARY);
threshold(inputPicture, inputPicture, thresholdBinary, 255, THRESH_BINARY);
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
Canny(inputPicture, inputPicture, 50, 100, 3);
Canny(inputPicture, inputPicture, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
}
std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)

View File

@ -19,7 +19,7 @@ public:
// End und Anfangspunkt analysieren und Winkel und Ausrichtung der Linie extrahieren (Abstand des untersten Punktes von der Mitte)
~Processing();
void processImage(Mat& inputPicture, int thresholdValue, int gaussKernelSize);
void processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
std::vector<Vec4i> calculateLineSegments(const Mat& inputPicture);
};

View File

@ -18,6 +18,9 @@ int main(void)
const int videoHeight = 720;
const int videoWidth = 960;
const int gaussKernelSize = 21;
const int thresholdCanny1 = 50;
const int thresholdCanny2 = 100;
const int apertureSizeCanny = 3;
@ -29,7 +32,7 @@ int main(void)
{
Mat image = input.readFile("Der\\Pfad\\zum\\Input\\Bilder\\Ordner\\auf\\deinem\\System");
Mat processedImage = image;
processing.processImage(processedImage, thresholdBinary, gaussKernelSize);
processing.processImage(processedImage, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2 ,apertureSizeCanny);
std::vector<Vec4i> lines = processing.calculateLineSegments(processedImage);
for( size_t i = 0; i < lines.size(); i++ )
{

View File

@ -10,8 +10,11 @@ int main(void)
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);
LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
lfr.startLoop();
//To end the video stream, write any char in the console.
char a;

View File

@ -1,12 +1,15 @@
#include "lfr.h"
LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize)
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()
@ -23,7 +26,7 @@ void LFR::loop()
while(iAmLooping)
{
Mat image = input.readWebcam();
processing.processImage(image, this->thresholdBinary, this->gaussKernelSize);
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++ )
{

5
lfr.h
View File

@ -27,11 +27,14 @@ class LFR
thread loopThread;
int thresholdBinary;
int gaussKernelSize;
int thresholdCanny1;
int thresholdCanny2;
int apertureSizeCanny;
public:
LFR() = delete;
LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize);
LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
~LFR();
void startLoop();