-
Notifications
You must be signed in to change notification settings - Fork 0
crucifix locator cv_solution
Xavier_ROV4/tasks/crucifix/locator/cv_solution/cpp_code/
Code is used to find the center of a cross coordinates. It was created with usage of OpenCV 4.1 library. It is based on Hough Lines algorithm which finds lines on a cross contour on thresholded image (both functions included in additional library - ImageProcessing).
Program takes each line and checks wether it is vertical or not (isVertical function) and counts average parameters of vertical lines. Afterwards it checks through all the non-vertical lines to find perpendicular ones (checkIfPerpendicular function) and also counts it's average. Parameters of this two average lines are used to find intersection point.
getIntersectionCoordinates returns map X:x_coordinates, Y:y_coordinates
map<string,double> CrossDetector::getIntersectionCoordinates(const cv::Mat& frame) { cv::Mat cloned_frame = frame.clone(); findLinesParameters(cloned_frame);
map<string, double> coordinates;
double d,x,y;
d = cos(averageParameters[0])*sin(averageParameters[2]) - cos(averageParameters[2])*sin(averageParameters[0]);
x = (sin(averageParameters[0]) * averageParameters[3] - sin(averageParameters[2])*averageParameters[1])/d;
y = (cos(averageParameters[0]) * averageParameters[3] - cos(averageParameters[2])*averageParameters[1])/d;
normalizeCoordinates(x, y, cloned_frame);
coordinates["x"] = x;
coordinates["y"] = y;
return coordinates;
}