Implement approach prev tested in spielwiese
This commit is contained in:
@@ -24,19 +24,37 @@ void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussK
|
||||
// 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);
|
||||
threshold(inputPicture, inputPicture, thresholdBinary, 255, THRESH_BINARY);
|
||||
|
||||
//Perform a opening
|
||||
Mat kernel(5,5, CV_8UC1,1);
|
||||
morphologyEx(inputPicture, inputPicture, 2, kernel);
|
||||
}
|
||||
|
||||
std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)
|
||||
FrameData Processing::calculateLineSegments(const Mat& inputPicture, const cv::Rect& roi)
|
||||
{
|
||||
//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;
|
||||
FrameData data;
|
||||
cv::findContours(inputPicture, data.contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
//Delete the areas that are too small
|
||||
auto iterator = data.contours.begin();
|
||||
while(iterator != data.contours.end())
|
||||
{
|
||||
if (contourArea(*iterator) < 3500)
|
||||
{
|
||||
iterator = data.contours.erase(iterator);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect boundingBox = boundingRect(*iterator);
|
||||
boundingBox.x += roi.x;
|
||||
boundingBox.y += roi.y;
|
||||
data.boundingBoxes.push_back(boundingBox);
|
||||
data.middlePoints.push_back(Point(boundingBox.x+boundingBox.width/2, boundingBox.y+boundingBox.height/2));
|
||||
data.leftEdges.push_back(Point(boundingBox.x, boundingBox.y+boundingBox.height/2));
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ public:
|
||||
|
||||
void processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny);
|
||||
|
||||
std::vector<Vec4i> calculateLineSegments(const Mat& inputPicture);
|
||||
FrameData calculateLineSegments(const Mat& inputPicture, const cv::Rect& roi);
|
||||
};
|
||||
Reference in New Issue
Block a user