|
|
@@ -82,58 +82,68 @@ void Processing::calcAngles(FrameData &data, int imageColums, int imageRows, boo |
|
|
|
|
|
|
|
if(data.contours.size() > 0) |
|
|
|
{ |
|
|
|
int angle = 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 index; |
|
|
|
// get the most left/right contour |
|
|
|
|
|
|
|
int leftmostEdge = imageColums; |
|
|
|
int rightmostEdge = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < data.leftEdges.size(); i++) |
|
|
|
{ |
|
|
|
int edge = data.leftEdges[i].x; |
|
|
|
|
|
|
|
if (edge <= leftmostEdge && turnLeft) |
|
|
|
{ |
|
|
|
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; |
|
|
|
leftmostEdge = edge; |
|
|
|
index = i; |
|
|
|
} |
|
|
|
else if(edge >= rightmostEdge && !turnLeft) |
|
|
|
{ |
|
|
|
rightmostEdge = edge; |
|
|
|
index = i; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Find the Top-Left and Bottom-Left Point of the Contour |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
std::vector<cv::Point> leftMostContour = data.contours[index]; |
|
|
|
|
|
|
|
/* |
|
|
|
Not going to dive into that part to fix it. |
|
|
|
Trying to use centroid instead. |
|
|
|
int xleftBottom = imageColums; |
|
|
|
int xleftTop = imageColums; |
|
|
|
int yBottom = 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 < xleftBottom) |
|
|
|
{ |
|
|
|
xleftBottom = 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 deltaX = abs(xleftBottom - xleftTop); |
|
|
|
int deltaY = yTop; |
|
|
|
angle = Calcs::calcAngle(deltaX, deltaY); |
|
|
|
*/ |
|
|
|
|
|
|
|
//Get the contours center using moments: |
|
|
|
cv::Moments moments=cv::moments(leftMostContour); |
|
|
|
LFRPoint contourCenter(moments.m10/moments.m00, moments.m01/moments.m00); |
|
|
|
LFRPoint imageCenter(double(imageColums)/2.0, double(imageRows)/2.0); |
|
|
|
LFRPoint focusPoint(imageCenter.x, imageCenter.y+1000.0); |
|
|
|
|
|
|
|
LFRVector a(imageCenter-focusPoint); |
|
|
|
LFRVector b(contourCenter-focusPoint); |
|
|
|
|
|
|
|
double angle = a.angle(b); |
|
|
|
|
|
|
|
//Write to Data |
|
|
|
data.angle = angle; |