openCVTexture.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file openCVTexture.h
  10. * @author zacpavlov
  11. * @date 2005-08-19
  12. */
  13. #ifndef OPENCVTEXTURE_H
  14. #define OPENCVTEXTURE_H
  15. #include "pandabase.h"
  16. #ifdef HAVE_OPENCV
  17. #include "videoTexture.h"
  18. struct CvCapture;
  19. /**
  20. * A specialization on VideoTexture that takes its input using the CV library,
  21. * to produce an animated texture, with its source taken from an .avi file or
  22. * from a camera input.
  23. */
  24. class EXPCL_VISION OpenCVTexture : public VideoTexture {
  25. PUBLISHED:
  26. OpenCVTexture(const std::string &name = std::string());
  27. OpenCVTexture(const OpenCVTexture &copy) = delete;
  28. virtual ~OpenCVTexture();
  29. bool from_camera(int camera_index = -1, int z = 0,
  30. int alpha_file_channel = 0,
  31. const LoaderOptions &options = LoaderOptions());
  32. public:
  33. static PT(Texture) make_texture();
  34. protected:
  35. virtual void consider_update();
  36. virtual PT(Texture) make_copy_impl() const;
  37. void do_assign(Texture::CData *cdata_tex, const OpenCVTexture *copy,
  38. const Texture::CData *cdata_copy_tex);
  39. virtual void do_update_frame(Texture::CData *cdata_tex, int frame);
  40. virtual void do_update_frame(Texture::CData *cdata_tex, int frame, int z);
  41. virtual bool do_read_one(Texture::CData *cdata,
  42. const Filename &fullpath, const Filename &alpha_fullpath,
  43. int z, int n, int primary_file_num_channels, int alpha_file_channel,
  44. const LoaderOptions &options,
  45. bool header_only, BamCacheRecord *record);
  46. virtual bool do_load_one(Texture::CData *cdata,
  47. const PNMImage &pnmimage, const std::string &name,
  48. int z, int n, const LoaderOptions &options);
  49. private:
  50. class VideoPage;
  51. class VideoStream;
  52. VideoPage &do_modify_page(const Texture::CData *cdata, int z);
  53. bool do_reconsider_video_properties(Texture::CData *cdata,
  54. const VideoStream &stream,
  55. int num_components, int z,
  56. const LoaderOptions &options);
  57. void do_update();
  58. class VideoStream {
  59. public:
  60. VideoStream();
  61. VideoStream(const VideoStream &copy);
  62. ~VideoStream();
  63. bool read(const Filename &filename);
  64. bool from_camera(int camera_index);
  65. void clear();
  66. INLINE bool is_valid() const;
  67. INLINE bool is_from_file() const;
  68. bool get_frame_data(int frame,
  69. const unsigned char *&r,
  70. const unsigned char *&g,
  71. const unsigned char *&b,
  72. int &x_pitch, int &y_pitch);
  73. CvCapture *_capture;
  74. Filename _filename;
  75. int _camera_index;
  76. int _next_frame;
  77. };
  78. class VideoPage {
  79. public:
  80. INLINE VideoPage();
  81. INLINE VideoPage(const VideoPage &copy);
  82. INLINE ~VideoPage();
  83. VideoStream _color, _alpha;
  84. };
  85. typedef pvector<VideoPage> Pages;
  86. Pages _pages;
  87. public:
  88. static void register_with_read_factory();
  89. public:
  90. static TypeHandle get_class_type() {
  91. return _type_handle;
  92. }
  93. static void init_type() {
  94. VideoTexture::init_type();
  95. register_type(_type_handle, "OpenCVTexture",
  96. VideoTexture::get_class_type());
  97. }
  98. virtual TypeHandle get_type() const {
  99. return get_class_type();
  100. }
  101. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  102. private:
  103. static TypeHandle _type_handle;
  104. };
  105. #include "openCVTexture.I"
  106. #endif // HAVE_OPENCV
  107. #endif