Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.h 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <opencv2/opencv.hpp>
  3. using namespace cv;
  4. using namespace std;
  5. class LFRPoint
  6. {
  7. private:
  8. /* data */
  9. public:
  10. double x, y;
  11. LFRPoint(/* args */);
  12. LFRPoint(double x, double y);
  13. ~LFRPoint();
  14. LFRPoint operator-(const LFRPoint& pt){return LFRPoint(x-pt.x, y-pt.y);}
  15. LFRPoint operator+(const LFRPoint& pt){return LFRPoint(x+pt.x, y+pt.y);}
  16. };
  17. class LFRVector : public LFRPoint
  18. {
  19. private:
  20. /* data */
  21. public:
  22. LFRVector(/* args */);
  23. LFRVector(double x, double y);
  24. LFRVector(const LFRPoint& pt);
  25. ~LFRVector();
  26. };
  27. class LFRLine
  28. {
  29. private:
  30. /* data */
  31. public:
  32. LFRPoint start;
  33. LFRVector dir;
  34. LFRLine(/* args */);
  35. LFRLine(LFRPoint start, LFRVector dir);
  36. LFRLine(LFRPoint start, LFRPoint end);
  37. ~LFRLine();
  38. };
  39. class VectorOfLines{
  40. private:
  41. public:
  42. Point startPoint;
  43. float gradient;
  44. float zeroPoint;
  45. VectorOfLines();
  46. ~VectorOfLines();
  47. static double calcGradient(Point x, Point y);
  48. float calcZeroPoint(cv::Point x, float m);
  49. static double calcDistance(Point p0, Point p1);
  50. vector<Vec4i> findMiddleLine(vector<Vec4i> &lines);
  51. static int calcAngle(int deltaX, int deltaY);
  52. };
  53. class FrameData
  54. {
  55. public:
  56. std::vector<std::vector<cv::Point>> contours;
  57. std::vector<cv::Rect> boundingBoxes;
  58. std::vector<cv::Point> leftEdges;
  59. std::vector<cv::Point> middlePoints;
  60. std::vector<double> angles;
  61. FrameData(): contours(), boundingBoxes(), leftEdges(), middlePoints() {}
  62. };