Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Point figurePos(Mat img, figure_t figure);
- Point figurePos(Mat img, figure_t figure) {
- Mat hsv;
- doMasc(img, &hsv, figure, AllRealFigures);
- vector<vector<Point>> contours;
- findContours(hsv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
- int squareMax = 500, squareBuff;
- int index = -1;
- for (int j = 0; j < contours.size(); j++) {
- squareBuff = contourArea(contours[j]);
- if (squareBuff > squareMax) {
- squareMax = squareBuff;
- index = j;
- }
- }
- if (index == -1) {
- return { 0, 0 };
- }
- RotatedRect rect = minAreaRect(contours[index]);
- Point2f vertices[4];
- rect.points(vertices);
- Point2f rightPoint = vertices[0];
- for (int i = 1; i < 4; i++) {
- if (rightPoint.x < vertices[i].x) {
- rightPoint = vertices[i];
- }
- }
- rightPoint.y = rect.center.y;
- circle(img, rightPoint, 1, Scalar(0, 255, 0), 3);
- return rightPoint;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement