Browse Source

Introduce variables for canny stuff instead of hardcoding

pull/1/head
Tim Zeuner 1 year ago
parent
commit
8611a47b75
6 changed files with 21 additions and 9 deletions
  1. 3
    3
      Processing/processing.cpp
  2. 1
    1
      Processing/processing.h
  3. 4
    1
      Spielwiese/spielwiese.cpp
  4. 4
    1
      autonomous_mode_main.cpp
  5. 5
    2
      lfr.cpp
  6. 4
    1
      lfr.h

+ 3
- 3
Processing/processing.cpp View File

return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10); 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: //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) // 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. // And one (the other one) to segment the lines.
// No return value here as the input is passed by reference -> directly modified. // No return value here as the input is passed by reference -> directly modified.
cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY); 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); 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) std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)

+ 1
- 1
Processing/processing.h View File

// End und Anfangspunkt analysieren und Winkel und Ausrichtung der Linie extrahieren (Abstand des untersten Punktes von der Mitte) // End und Anfangspunkt analysieren und Winkel und Ausrichtung der Linie extrahieren (Abstand des untersten Punktes von der Mitte)
~Processing(); ~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); std::vector<Vec4i> calculateLineSegments(const Mat& inputPicture);
}; };

+ 4
- 1
Spielwiese/spielwiese.cpp View File

const int videoHeight = 720; const int videoHeight = 720;
const int videoWidth = 960; const int videoWidth = 960;
const int gaussKernelSize = 21; const int gaussKernelSize = 21;
const int thresholdCanny1 = 50;
const int thresholdCanny2 = 100;
const int apertureSizeCanny = 3;






{ {
Mat image = input.readFile("Der\\Pfad\\zum\\Input\\Bilder\\Ordner\\auf\\deinem\\System"); Mat image = input.readFile("Der\\Pfad\\zum\\Input\\Bilder\\Ordner\\auf\\deinem\\System");
Mat processedImage = image; Mat processedImage = image;
processing.processImage(processedImage, thresholdBinary, gaussKernelSize);
processing.processImage(processedImage, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2 ,apertureSizeCanny);
std::vector<Vec4i> lines = processing.calculateLineSegments(processedImage); std::vector<Vec4i> lines = processing.calculateLineSegments(processedImage);
for( size_t i = 0; i < lines.size(); i++ ) for( size_t i = 0; i < lines.size(); i++ )
{ {

+ 4
- 1
autonomous_mode_main.cpp View File

const int videoHeight = 240; const int videoHeight = 240;
const int videoWidth = 320; const int videoWidth = 320;
const int gaussKernelSize = 21; 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(); lfr.startLoop();
//To end the video stream, write any char in the console. //To end the video stream, write any char in the console.
char a; char a;

+ 5
- 2
lfr.cpp View File

#include "lfr.h" #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() : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler()
{ {
this->iAmLooping = false; this->iAmLooping = false;
this->thresholdBinary = thresholdBinary; this->thresholdBinary = thresholdBinary;
this->gaussKernelSize = gaussKernelSize; this->gaussKernelSize = gaussKernelSize;
this->thresholdCanny1 = thresholdCanny1;
this->thresholdCanny2 = thresholdCanny2;
this->apertureSizeCanny = apertureSizeCanny;
} }


LFR::~LFR() LFR::~LFR()
while(iAmLooping) while(iAmLooping)
{ {
Mat image = input.readWebcam(); 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); std::vector<Vec4i> lines = processing.calculateLineSegments(image);
for( size_t i = 0; i < lines.size(); i++ ) for( size_t i = 0; i < lines.size(); i++ )
{ {

+ 4
- 1
lfr.h View File

thread loopThread; thread loopThread;
int thresholdBinary; int thresholdBinary;
int gaussKernelSize; int gaussKernelSize;
int thresholdCanny1;
int thresholdCanny2;
int apertureSizeCanny;


public: public:


LFR() = delete; 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(); ~LFR();


void startLoop(); void startLoop();

Loading…
Cancel
Save