Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int isFigure(Mat img, figure_t figure) {
- Mat hsv;
- vector<vector<Point>> contours;
- doMasc(img, &hsv, figure, AllRealFigures);
- findContours(hsv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
- bool ans = 0;
- for (int j = 0; j < contours.size(); j++)
- ans = ans || (MAX_FIGURE_SQUARE < contourArea(contours[j]));
- return ans;
- }
- figure_t GetFigure(Mat img) {
- Mat hsv;
- vector<vector<Point>> contours;
- figure_t maxFoundFigure = Free_f;
- int buffDistance;
- Rect FigureRect;
- Point center = ((img.size().width / 2.0), (img.size().height / 2.0));
- int distanceFigure = 10000000;//distance2Center((img.size().width), (img.size().height), center);
- for (int i = 0; i < NUMBER_REAL_FIGURE; i++) {
- doMasc(img, &hsv, (figure_t)(i + 1), AllRealFigures);
- findContours(hsv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
- //waitKey(0);
- for (int j = 0; j < contours.size(); j++) {
- if (MAX_FIGURE_SQUARE < contourArea(contours[j])) {
- Rect rect = boundingRect(contours[j]);
- buffDistance = distance2Center(rect.x + (rect.width / 2.0), rect.y + (rect.height / 2.0), center);
- if (buffDistance < distanceFigure) {
- if (((i == 2) || (i == 5))) { //j or i
- RotatedRect r_rect = minAreaRect(contours[j]);
- Size size;
- size.width = min(r_rect.size.height, r_rect.size.width);
- size.height = max(r_rect.size.height, r_rect.size.width);
- if (((i == 2) && (size.height / (double)size.width) < 3.2) || ((i == 5) && (size.height / (double)size.width) >= 3.2)) {
- distanceFigure = buffDistance;
- maxFoundFigure = (figure_t)(i + 1);
- FigureRect = rect;
- }
- continue;
- }
- distanceFigure = buffDistance;
- maxFoundFigure = (figure_t)(i + 1);
- FigureRect = rect;
- }
- }
- }
- }
- return maxFoundFigure;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement