Winkelerkennung
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "processing.h"
|
||||
|
||||
|
||||
|
||||
|
||||
Processing::Processing(/* args */)
|
||||
{
|
||||
}
|
||||
@@ -47,6 +50,7 @@ void Processing::filterReflections(FrameData& frameData)
|
||||
indicesToDelete.push_back(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//reverse the vector with the indices so the order isn't messed up when deleting:
|
||||
@@ -82,6 +86,66 @@ bool Processing::checkIntersection(const std::vector<std::vector<Point>>& lines,
|
||||
return true;
|
||||
}
|
||||
|
||||
int Processing::calcAngles(FrameData &data, int imageColums, int imageRows, bool turnLeft)
|
||||
{
|
||||
int angle = 0;
|
||||
if(data.contours.size() > 0)
|
||||
{
|
||||
int index;
|
||||
if(turnLeft){
|
||||
// get the most left/right contour
|
||||
int leftmostEdge = imageColums;
|
||||
|
||||
for (int i = 0; i < data.leftEdges.size(); i++)
|
||||
{
|
||||
int edge = data.leftEdges[i].x;
|
||||
|
||||
if (edge <= leftmostEdge)
|
||||
{
|
||||
leftmostEdge = edge;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
int rightmostEdge = 0;
|
||||
|
||||
for (int i = 0; i < data.leftEdges.size(); i++)
|
||||
{
|
||||
int edge = data.leftEdges[i].x;
|
||||
|
||||
if (edge >= rightmostEdge)
|
||||
{
|
||||
rightmostEdge = edge;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Find the Top-Left and Buttom-Left Point of the Contour
|
||||
|
||||
std::vector<cv::Point> leftMostContour = data.contours[index];
|
||||
int xleftButtom = imageColums;
|
||||
int xleftTop = imageColums;
|
||||
int yButtom = data.boundingBoxes[index].y;
|
||||
int yTop = data.boundingBoxes[index].height;
|
||||
|
||||
for (int i = 0; i < leftMostContour.size(); i++){
|
||||
if(leftMostContour[i].y == 0 && leftMostContour[i].x < xleftButtom)
|
||||
{
|
||||
xleftButtom = leftMostContour[i].x;
|
||||
}else if(leftMostContour[i].y > yTop -4 && leftMostContour[i].x < xleftTop){
|
||||
xleftTop = leftMostContour[i].x;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate angle
|
||||
int deltaX = abs(xleftButtom - xleftTop);
|
||||
int deltaY = yTop;
|
||||
angle = VectorOfLines::calcAngle(deltaX, deltaY);
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize)
|
||||
{
|
||||
@@ -126,7 +190,7 @@ FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& r
|
||||
auto iterator = data.contours.begin();
|
||||
while(iterator != data.contours.end())
|
||||
{
|
||||
if (contourArea(*iterator) < 3500)
|
||||
if (contourArea(*iterator) < 7000)
|
||||
{
|
||||
iterator = data.contours.erase(iterator);
|
||||
}
|
||||
@@ -137,8 +201,6 @@ FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& r
|
||||
else
|
||||
{
|
||||
//Check for intersection with lines:
|
||||
|
||||
|
||||
Rect boundingBox = boundingRect(*iterator);
|
||||
boundingBox.x += roi.x;
|
||||
boundingBox.y += roi.y;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <utils.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
@@ -23,4 +24,5 @@ public:
|
||||
void processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize);
|
||||
void filterReflections(FrameData& frameData);
|
||||
FrameData calculateLineSegments(Mat& inputPicture, const cv::Rect& roi);
|
||||
int calcAngles(FrameData &data, int imageColums, int imageRows, bool turnLeft);
|
||||
};
|
||||
Reference in New Issue
Block a user