NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
FieldDetector.hpp
1 //FieldDetector.hpp
2 // Created on: May 12, 2015
3 // Author: Hafez Farazi <farazi@ais.uni-bonn.de>
4 #pragma once
5 #include <opencv2/opencv.hpp>
6 #include <math.h>
7 #include <vision_module/SoccerObjects/IContourDetector.hpp>
8 #include <vision_module/Tools/Parameters.hpp>
9 #include <vision_module/Tools/General.hpp>
10 #include <vision_module/Tools/SortFuntions.hpp>
11 #include <algorithm> // std::sort
12 
13 using namespace cv;
19 class FieldDetector: public IDetector
20 {
21 public:
22  inline ~FieldDetector()
23  {
24  }
25  vector<cv::Point> BodyMaskContourInverted;
26  bool GetPoints(Mat &binaryFrame, vector<Point> &resPoints,
27  vector<vector<Point> > &allFieldContours);
28  void FindInField(const Mat &srcHsvImg, const Mat &tmplateGrayImg,
29  Mat *dstGrayImgs, hsvRangeC *ranges, bool *inTemplate,
30  int size = 1);
31  inline bool Init()
32  {
33  cv::FileStorage fr(params.configPath+"BodyMask.yml",
34  cv::FileStorage::READ);
35  cv::FileNode fileNode = fr["IGUS"];
36  read(fileNode, BodyMaskContourInverted);
37  fr.release();
38  if (BodyMaskContourInverted.size() < 6)
39  {
40  ROS_ERROR("Create or modify BodyMask.yml!");
41  }
42 
43  return true;
44  }
45  vector<cv::Point> getBodyMaskContourInRaw(float rot)
46  {
47  vector<cv::Point> res;
48  if (BodyMaskContourInverted.size() < 6)
49  return res;
50  for (size_t i = 0; i < BodyMaskContourInverted.size(); i++)
51  {
52 
53  cv::Point rotated = RotateAroundPoint(BodyMaskContourInverted[i],
54  rot);
55  cv::Point p(rotated.x + params.camera->width() / 2.,
56  abs(rotated.y - 480));
57  if (p.inside(
58  cv::Rect(0, 0, params.camera->width(),
59  params.camera->height())))
60  {
61  if (res.size() == 0)
62  {
63  res.push_back(cv::Point(p.x, params.camera->height()));
64  }
65  res.push_back(p);
66  }
67  }
68  if (res.size() > 0)
69  {
70  int xlast = res[res.size() - 1].x;
71  res.push_back(cv::Point(xlast, params.camera->height()));
72  }
73  return res;
74  }
75 };
76 
For detecting field boundary.
Definition: FieldDetector.hpp:19
HSV range class.
Definition: Parameters.hpp:126