43 lines
1.4 KiB
C++
Raw Normal View History

2022-11-01 14:18:02 +01:00
#include "processing.h"
2022-11-01 14:29:11 +01:00
Processing::Processing(/* args */)
2022-11-01 14:18:02 +01:00
{
}
2022-11-01 14:29:11 +01:00
Processing::~Processing()
2022-11-01 14:18:02 +01:00
{
}
2022-11-14 11:37:38 +01:00
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 thresholdValue, 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)
// 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);
2022-11-15 17:33:20 +01:00
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
Canny(inputPicture, inputPicture, 50, 100, 3);
}
2022-11-15 17:33:20 +01:00
std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)
{
2022-11-15 17:33:20 +01:00
//See following link
2022-11-10 21:14:47 +01:00
//https://stackoverflow.com/questions/45322630/how-to-detect-lines-in-opencv
2022-11-15 17:33:20 +01:00
vector<Vec4i> lines;
VectorOfLines linesInVectors;
HoughLinesP(inputPicture, lines, 1, CV_PI/360, 150, 0, 250);
//lines = linesInVectors.findMiddleLine(lines);
return lines;
}