Browse Source

Remove unused canny parameters from processing and lfr, tried to get hughlinesp back in for reflection removal

master
Tim Zeuner 2 years ago
parent
commit
aec322031e

+ 19
- 5
AutonomousMode/Processing/processing.cpp View File

@@ -79,7 +79,7 @@ void Processing::filterReflections(FrameData& frameData)
return;
}

void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize)
{
//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)
@@ -88,16 +88,30 @@ void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussK
cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY);
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
threshold(inputPicture, inputPicture, thresholdBinary, 255, THRESH_BINARY);
//Perform a opening
//Perform an opening
Mat kernel(5,5, CV_8UC1,1);
morphologyEx(inputPicture, inputPicture, 2, kernel);
}

FrameData Processing::calculateLineSegments(const Mat& inputPicture, const cv::Rect& roi)
FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& roi)
{

FrameData data;
cv::findContours(inputPicture, data.contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
Mat inputPictureRoi = inputPicture(roi);
cv::findContours(inputPictureRoi, data.contours, RETR_LIST, CHAIN_APPROX_SIMPLE);

vector<Vec4i> lines;
Canny(inputPicture, inputPicture, 50, 100, 3);
HoughLinesP(inputPicture, lines, 1, CV_PI/180, 100, 30, 50);
//Draw lines
inputPicture = Mat::zeros(inputPicture.size().height, inputPicture.size().width, CV_8UC1);

for( size_t i = 0; i < lines.size(); i++ )
{
line( inputPicture, Point(lines[i][0], lines[i][1]), Point(lines[i][2], lines[i][3]), Scalar(255,255,255), 3, 8 );
}


//Delete the areas that are too small
auto iterator = data.contours.begin();

+ 2
- 2
AutonomousMode/Processing/processing.h 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 thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
void processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize);
void filterReflections(FrameData& frameData);
FrameData calculateLineSegments(const Mat& inputPicture, const cv::Rect& roi);
FrameData calculateLineSegments(Mat& inputPicture, const cv::Rect& roi);
};

+ 2
- 5
AutonomousMode/autonomous_mode_main.cpp View File

@@ -9,12 +9,9 @@ int main(void)
const int thresholdBinary = 140;
const int videoHeight = 720;
const int videoWidth = 1280;
const int gaussKernelSize = 21;
const int thresholdCanny1 = 50;
const int thresholdCanny2 = 100;
const int apertureSizeCanny = 3;
const int gaussKernelSize = 11;

LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize);
lfr.saveOutputFlag = false;
lfr.videoFlag = true;
lfr.startLoop();

+ 14
- 14
AutonomousMode/lfr.cpp View File

@@ -1,15 +1,12 @@
#include "lfr.h"


LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize)
: 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;

this->videoFlag = false;
this->saveOutputFlag = false;
@@ -33,12 +30,14 @@ void LFR::loop()

Point roiOrigin(0, int(originalImage.rows*(7.5/12.0)));
Rect roi(roiOrigin.x, roiOrigin.y, originalImage.cols, originalImage.rows/12);
Mat processedImage = originalImage(roi);
//Mat processedImage = originalImage(roi);
Mat processedImage = originalImage;

processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize);
//processedImage = processedImage(roi);
FrameData data = processing.calculateLineSegments(processedImage, roi);
processing.filterReflections(data);
this->provideOutput(originalImage, data, roi);
this->provideOutput(originalImage, processedImage, data, roi);
}
if(this->videoFlag) {destroyWindow("Display window");}
input.freeWebcam();
@@ -57,25 +56,26 @@ void LFR::endLoop()
return;
}

void LFR::provideOutput(Mat image, const FrameData& frameData, const Rect& roi)
void LFR::provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi)
{
for(int i = 0; i < frameData.contours.size(); i++)
{
drawContours(image, frameData.contours, i, Scalar(0,255,255), 1, 8, noArray(), 0, Point(roi.x, roi.y));
drawContours(originalImage, frameData.contours, i, Scalar(0,255,255), 1, 8, noArray(), 0, Point(roi.x, roi.y));

rectangle(image, frameData.boundingBoxes[i], Scalar(0,255,0));
rectangle(originalImage, frameData.boundingBoxes[i], Scalar(0,255,0));
Rect center(Point(frameData.middlePoints[i].x-2, frameData.middlePoints[i].y-2), Point(frameData.middlePoints[i].x+2, frameData.middlePoints[i].y+2));
rectangle(image, center, Scalar(0,0,255));
rectangle(originalImage, center, Scalar(0,0,255));
Rect leftRect(Point(frameData.leftEdges[i].x-2, frameData.leftEdges[i].y-2), Point(frameData.leftEdges[i].x+2, frameData.leftEdges[i].y+2));
rectangle(image, leftRect, Scalar(0,0,255));
rectangle(originalImage, leftRect, Scalar(0,0,255));
}
if(this->videoFlag)
{
imshow("Display window", image);
imshow("Display window", originalImage);
imshow("processed:", processedImage);
char c = (char)waitKey(25);
}
if (this->saveOutputFlag && !(this->outputFileName.empty()))
{
imwrite(this->outputFileName, image);
imwrite(this->outputFileName, originalImage);
}
}

+ 2
- 5
AutonomousMode/lfr.h View File

@@ -27,16 +27,13 @@ class LFR
thread loopThread;
int thresholdBinary;
int gaussKernelSize;
int thresholdCanny1;
int thresholdCanny2;
int apertureSizeCanny;

void provideOutput(Mat image,const FrameData& frameData, const Rect& roi);
void provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);

public:

LFR() = delete;
LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize);
~LFR();

void startLoop();

Loading…
Cancel
Save