No Description
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.

img.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2018 dimercur
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __IMG_H__
  18. #define __IMG_H__
  19. #include <iostream>
  20. #include <list>
  21. #include <string>
  22. #include <opencv2/highgui/highgui.hpp>
  23. #include <opencv2/imgproc/imgproc.hpp>
  24. #include <opencv2/core.hpp>
  25. #ifdef __WITH_ARUCO__
  26. #include <opencv2/aruco/dictionary.hpp>
  27. #include <opencv2/aruco/charuco.hpp>
  28. #include <opencv2/core/mat.hpp>
  29. #endif // __WITH_ARUCO__
  30. #define ARENA_NOT_DETECTED -1
  31. using namespace std;
  32. typedef cv::Mat ImageMat;
  33. typedef vector<unsigned char> Jpg;
  34. typedef struct {
  35. cv::Point2f center;
  36. cv::Point2f direction;
  37. float angle;
  38. int robotId;
  39. } Position;
  40. class Arene {
  41. public:
  42. Arene() {}
  43. cv::Rect arene;
  44. bool empty();
  45. };
  46. class Img {
  47. public:
  48. Img(ImageMat imgMatrice);
  49. string ToString();
  50. Img* Copy();
  51. Jpg toJpg();
  52. string ToBase64();
  53. Arene search_arena();
  54. int draw_robot(Position robot);
  55. int draw_all_robots(std::list<Position> robots);
  56. int draw_arena(Arene areneToDraw);
  57. std::list<Position> search_robot(Arene monArene);
  58. #ifdef __WITH_ARUCO__
  59. list<Position> search_aruco(Arene monArene = NULL);
  60. #endif // __WITH_ARUCO__
  61. private:
  62. ImageMat img;
  63. #ifdef __WITH_ARUCO__
  64. Ptr<std::Dictionary> dictionary;
  65. cv::Point2f find_aruco_center(std::vector<cv::Point2f> aruco);
  66. cv::Point2f find_aruco_direction(std::vector<cv::Point2f> aruco);
  67. #endif // __WITH_ARUCO__
  68. float calculAngle(Position robots);
  69. float calculAngle2(cv::Point2f pt1, cv::Point2f pt2);
  70. float euclideanDist(cv::Point2f p, cv::Point2f q);
  71. ImageMat cropArena(Arene arene);
  72. };
  73. #endif //__IMG_H__