CFindTemplate._h_ 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #ifndef __CFINDTEMPLATE
  3. #define __CFINGTEMPLATE
  4. #include <stdint.h>
  5. #include <string>
  6. #define _USE_MATH_DEFINES
  7. #include <math.h>
  8. #include <esp_heap_caps.h>
  9. #include "stb_image.h"
  10. #include "stb_image_write.h"
  11. #include "stb_image_resize.h"
  12. class CImageBasis
  13. {
  14. protected:
  15. uint8_t* rgb_image;
  16. int channels;
  17. int width, height, bpp;
  18. bool externalImage;
  19. std::string filename;
  20. void memCopy(uint8_t* _source, uint8_t* _target, int _size);
  21. public:
  22. int getWidth(){return this->width;};
  23. int getHeight(){return this->width;};
  24. int getChannels(){return this->channels;};
  25. CImageBasis();
  26. CImageBasis(std::string _image);
  27. CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
  28. uint8_t GetPixelColor(int x, int y, int ch);
  29. ~CImageBasis();
  30. void SaveToFile(std::string _imageout);
  31. };
  32. class CFindTemplate : public CImageBasis
  33. {
  34. public:
  35. CFindTemplate(std::string _image);
  36. void FindTemplate(std::string _template, int* found_x, int* found_y, std::string _imageout);
  37. void FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy, std::string _imageout);
  38. void FindTemplate(std::string _template, int* found_x, int* found_y);
  39. void FindTemplate(std::string _template, int* found_x, int* found_y, int _dx, int _dy);
  40. };
  41. class CRotate: public CImageBasis
  42. {
  43. public:
  44. CRotate(std::string _image) : CImageBasis(_image) {};
  45. CRotate(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) : CImageBasis(_rgb_image, _channels, _width, _height, _bpp) {};
  46. void Rotate(float _angle);
  47. void Rotate(float _angle, int _centerx, int _centery);
  48. void Translate(int _dx, int _dy);
  49. };
  50. class CAlignAndCutImage : public CImageBasis
  51. {
  52. public:
  53. CAlignAndCutImage(std::string _image) : CImageBasis(_image) {};
  54. void Align(std::string _template0, int ref0_x, int ref0_y, std::string _template1, int ref1_x, int ref1_y, int deltax, int deltay);
  55. void CutAndSave(std::string _template1, int x1, int y1, int dx, int dy);
  56. };
  57. class CResizeImage : public CImageBasis
  58. {
  59. public:
  60. CResizeImage(std::string _image) : CImageBasis(_image) {};
  61. void Resize(int _new_dx, int _new_dy);
  62. };
  63. #endif