Compare commits
No commits in common. "2af8bfa536c911ddff5181ea8371616bac40de12" and "ea33e0b065bee87c8eb2f108910363fdf26a281f" have entirely different histories.
2af8bfa536
...
ea33e0b065
@ -82,68 +82,58 @@ void Processing::calcAngles(FrameData &data, int imageColums, int imageRows, boo
|
|||||||
|
|
||||||
if(data.contours.size() > 0)
|
if(data.contours.size() > 0)
|
||||||
{
|
{
|
||||||
int index;
|
int angle = 0;
|
||||||
// get the most left/right contour
|
int index;
|
||||||
|
if(turnLeft){
|
||||||
int leftmostEdge = imageColums;
|
// get the most left/right contour
|
||||||
int rightmostEdge = 0;
|
int leftmostEdge = imageColums;
|
||||||
|
|
||||||
for (int i = 0; i < data.leftEdges.size(); i++)
|
for (int i = 0; i < data.leftEdges.size(); i++)
|
||||||
{
|
{
|
||||||
int edge = data.leftEdges[i].x;
|
int edge = data.leftEdges[i].x;
|
||||||
|
|
||||||
if (edge <= leftmostEdge && turnLeft)
|
if (edge <= leftmostEdge)
|
||||||
|
{
|
||||||
|
leftmostEdge = edge;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
{
|
{
|
||||||
leftmostEdge = edge;
|
int rightmostEdge = 0;
|
||||||
index = i;
|
|
||||||
}
|
for (int i = 0; i < data.leftEdges.size(); i++)
|
||||||
else if(edge >= rightmostEdge && !turnLeft)
|
{
|
||||||
{
|
int edge = data.leftEdges[i].x;
|
||||||
rightmostEdge = edge;
|
|
||||||
index = i;
|
if (edge >= rightmostEdge)
|
||||||
}
|
{
|
||||||
}
|
rightmostEdge = edge;
|
||||||
|
index = i;
|
||||||
// Find the Top-Left and Bottom-Left Point of the Contour
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Find the Top-Left and Buttom-Left Point of the Contour
|
||||||
|
|
||||||
std::vector<cv::Point> leftMostContour = data.contours[index];
|
std::vector<cv::Point> leftMostContour = data.contours[index];
|
||||||
|
int xleftButtom = imageColums;
|
||||||
/*
|
int xleftTop = imageColums;
|
||||||
Not going to dive into that part to fix it.
|
int yButtom = data.boundingBoxes[index].y;
|
||||||
Trying to use centroid instead.
|
int yTop = data.boundingBoxes[index].height;
|
||||||
int xleftBottom = imageColums;
|
|
||||||
int xleftTop = imageColums;
|
for (int i = 0; i < leftMostContour.size(); i++){
|
||||||
int yBottom = data.boundingBoxes[index].y;
|
if(leftMostContour[i].y == 0 && leftMostContour[i].x < xleftButtom)
|
||||||
int yTop = data.boundingBoxes[index].height;
|
{
|
||||||
|
xleftButtom = leftMostContour[i].x;
|
||||||
for (int i = 0; i < leftMostContour.size(); i++)
|
}else if(leftMostContour[i].y > yTop -4 && leftMostContour[i].x < xleftTop){
|
||||||
{
|
xleftTop = leftMostContour[i].x;
|
||||||
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
|
// calculate angle
|
||||||
int deltaX = abs(xleftBottom - xleftTop);
|
int deltaX = abs(xleftButtom - xleftTop);
|
||||||
int deltaY = yTop;
|
int deltaY = yTop;
|
||||||
angle = Calcs::calcAngle(deltaX, deltaY);
|
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
|
//Write to Data
|
||||||
data.angle = angle;
|
data.angle = angle;
|
||||||
|
@ -139,13 +139,12 @@ cv::Mat LFR::provideOutput(Mat originalImage, Mat processedImage, const FrameDat
|
|||||||
{
|
{
|
||||||
//Draw the Arrow for the check of the angle
|
//Draw the Arrow for the check of the angle
|
||||||
int length = 100;
|
int length = 100;
|
||||||
|
Point P1 = frameData.middlePoints[frameData.index];
|
||||||
|
Point P2;
|
||||||
|
|
||||||
Point contourCenter = frameData.middlePoints[frameData.index];
|
P2.x = (int)round(P1.x + length * cos(frameData.angle * CV_PI / 180.0));
|
||||||
Point imageCenter = Point(originalImage.size().width/2.0, originalImage.size().height/2.0);
|
P2.y = (int)round(P1.y + length * sin(frameData.angle * CV_PI / 180.0));
|
||||||
Point focalPoint = Point(imageCenter.x, imageCenter.y+1000.0);
|
cv::arrowedLine(originalImage, P1, P2, Scalar(0,0,255), 2, 8);
|
||||||
|
|
||||||
cv::arrowedLine(originalImage, focalPoint, contourCenter, Scalar(0,0,255), 2, 8);
|
|
||||||
cv::arrowedLine(originalImage, focalPoint, imageCenter, Scalar(0,0,255), 2, 8);
|
|
||||||
}
|
}
|
||||||
return originalImage;
|
return originalImage;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user