Panda3D
|
00001 // Filename: openCVTexture.h 00002 // Created by: zacpavlov (19Aug05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef OPENCVTEXTURE_H 00016 #define OPENCVTEXTURE_H 00017 00018 #include "pandabase.h" 00019 #ifdef HAVE_OPENCV 00020 00021 #include "videoTexture.h" 00022 00023 #include <cxcore.h> 00024 #include <cv.h> 00025 #include <highgui.h> 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : OpenCVTexture 00029 // Description : A specialization on VideoTexture that takes its input 00030 // using the CV library, to produce an animated texture, 00031 // with its source taken from an .avi file or from a 00032 // camera input. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_VISION OpenCVTexture : public VideoTexture { 00035 PUBLISHED: 00036 OpenCVTexture(const string &name = string()); 00037 protected: 00038 OpenCVTexture(const OpenCVTexture ©); 00039 PUBLISHED: 00040 virtual ~OpenCVTexture(); 00041 00042 bool from_camera(int camera_index = -1, int z = 0, 00043 int alpha_file_channel = 0, 00044 const LoaderOptions &options = LoaderOptions()); 00045 00046 public: 00047 static PT(Texture) make_texture(); 00048 00049 protected: 00050 virtual void consider_update(); 00051 virtual PT(Texture) make_copy_impl(); 00052 void do_assign(Texture::CData *cdata_tex, const OpenCVTexture *copy, 00053 const Texture::CData *cdata_copy_tex); 00054 00055 virtual void do_update_frame(Texture::CData *cdata_tex, int frame); 00056 virtual void do_update_frame(Texture::CData *cdata_tex, int frame, int z); 00057 00058 virtual bool do_read_one(Texture::CData *cdata, 00059 const Filename &fullpath, const Filename &alpha_fullpath, 00060 int z, int n, int primary_file_num_channels, int alpha_file_channel, 00061 const LoaderOptions &options, 00062 bool header_only, BamCacheRecord *record); 00063 virtual bool do_load_one(Texture::CData *cdata, 00064 const PNMImage &pnmimage, const string &name, 00065 int z, int n, const LoaderOptions &options); 00066 00067 private: 00068 class VideoPage; 00069 class VideoStream; 00070 00071 VideoPage &do_modify_page(const Texture::CData *cdata, int z); 00072 bool do_reconsider_video_properties(Texture::CData *cdata, 00073 const VideoStream &stream, 00074 int num_components, int z, 00075 const LoaderOptions &options); 00076 void do_update(); 00077 00078 class VideoStream { 00079 public: 00080 VideoStream(); 00081 VideoStream(const VideoStream ©); 00082 ~VideoStream(); 00083 00084 bool read(const Filename &filename); 00085 bool from_camera(int camera_index); 00086 void clear(); 00087 INLINE bool is_valid() const; 00088 INLINE bool is_from_file() const; 00089 bool get_frame_data(int frame, 00090 const unsigned char *&r, 00091 const unsigned char *&g, 00092 const unsigned char *&b, 00093 int &x_pitch, int &y_pitch); 00094 00095 CvCapture *_capture; 00096 Filename _filename; 00097 int _camera_index; 00098 int _next_frame; 00099 }; 00100 00101 class VideoPage { 00102 public: 00103 INLINE VideoPage(); 00104 INLINE VideoPage(const VideoPage ©); 00105 INLINE ~VideoPage(); 00106 00107 VideoStream _color, _alpha; 00108 }; 00109 00110 typedef pvector<VideoPage> Pages; 00111 Pages _pages; 00112 00113 public: 00114 static void register_with_read_factory(); 00115 00116 public: 00117 static TypeHandle get_class_type() { 00118 return _type_handle; 00119 } 00120 static void init_type() { 00121 VideoTexture::init_type(); 00122 register_type(_type_handle, "OpenCVTexture", 00123 VideoTexture::get_class_type()); 00124 } 00125 virtual TypeHandle get_type() const { 00126 return get_class_type(); 00127 } 00128 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00129 00130 private: 00131 static TypeHandle _type_handle; 00132 }; 00133 00134 #include "openCVTexture.I" 00135 00136 #endif // HAVE_OPENCV 00137 00138 #endif