Panda3D
openCVTexture.h
Go to the documentation of this file.
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 
14 #ifndef OPENCVTEXTURE_H
15 #define OPENCVTEXTURE_H
16 
17 #include "pandabase.h"
18 #ifdef HAVE_OPENCV
19 
20 #include "videoTexture.h"
21 
22 struct CvCapture;
23 
24 /**
25  * A specialization on VideoTexture that takes its input using the CV library,
26  * to produce an animated texture, with its source taken from an .avi file or
27  * from a camera input.
28  */
29 class EXPCL_VISION OpenCVTexture : public VideoTexture {
30 PUBLISHED:
31  OpenCVTexture(const std::string &name = std::string());
32  OpenCVTexture(const OpenCVTexture &copy) = delete;
33  virtual ~OpenCVTexture();
34 
35  bool from_camera(int camera_index = -1, int z = 0,
36  int alpha_file_channel = 0,
37  const LoaderOptions &options = LoaderOptions());
38 
39 public:
40  static PT(Texture) make_texture();
41 
42 protected:
43  virtual void consider_update();
44  virtual PT(Texture) make_copy_impl() const;
45  void do_assign(Texture::CData *cdata_tex, const OpenCVTexture *copy,
46  const Texture::CData *cdata_copy_tex);
47 
48  virtual void do_update_frame(Texture::CData *cdata_tex, int frame);
49  virtual void do_update_frame(Texture::CData *cdata_tex, int frame, int z);
50 
51  virtual bool do_read_one(Texture::CData *cdata,
52  const Filename &fullpath, const Filename &alpha_fullpath,
53  int z, int n, int primary_file_num_channels, int alpha_file_channel,
54  const LoaderOptions &options,
55  bool header_only, BamCacheRecord *record);
56  virtual bool do_load_one(Texture::CData *cdata,
57  const PNMImage &pnmimage, const std::string &name,
58  int z, int n, const LoaderOptions &options);
59 
60 private:
61  class VideoPage;
62  class VideoStream;
63 
64  VideoPage &do_modify_page(const Texture::CData *cdata, int z);
65  bool do_reconsider_video_properties(Texture::CData *cdata,
66  const VideoStream &stream,
67  int num_components, int z,
68  const LoaderOptions &options);
69  void do_update();
70 
71  class VideoStream {
72  public:
73  VideoStream();
74  VideoStream(const VideoStream &copy);
75  ~VideoStream();
76 
77  bool read(const Filename &filename);
78  bool from_camera(int camera_index);
79  void clear();
80  INLINE bool is_valid() const;
81  INLINE bool is_from_file() const;
82  bool get_frame_data(int frame,
83  const unsigned char *&r,
84  const unsigned char *&g,
85  const unsigned char *&b,
86  int &x_pitch, int &y_pitch);
87 
88  CvCapture *_capture;
89  Filename _filename;
90  int _camera_index;
91  int _next_frame;
92  };
93 
94  class VideoPage {
95  public:
96  INLINE VideoPage();
97  INLINE VideoPage(const VideoPage &copy);
98  INLINE ~VideoPage();
99 
100  VideoStream _color, _alpha;
101  };
102 
103  typedef pvector<VideoPage> Pages;
104  Pages _pages;
105 
106 public:
107  static void register_with_read_factory();
108 
109 public:
110  static TypeHandle get_class_type() {
111  return _type_handle;
112  }
113  static void init_type() {
114  VideoTexture::init_type();
115  register_type(_type_handle, "OpenCVTexture",
116  VideoTexture::get_class_type());
117  }
118  virtual TypeHandle get_type() const {
119  return get_class_type();
120  }
121  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
122 
123 private:
124  static TypeHandle _type_handle;
125 };
126 
127 #include "openCVTexture.I"
128 
129 #endif // HAVE_OPENCV
130 
131 #endif
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
static void register_with_read_factory()
Factory method to generate a Texture object.
Definition: texture.cxx:9830
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The base class for a family of animated Textures that take their input from a video source,...
Definition: videoTexture.h:28
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.