Changes to get OpenCV webcam working

This commit is contained in:
rdb 2009-01-15 18:34:58 +00:00
parent f808e0a03b
commit 9861d44f82
4 changed files with 100 additions and 58 deletions

View File

@ -52,11 +52,11 @@ protected:
virtual void reconsider_dirty();
virtual void do_reload_ram_image();
INLINE void consider_update();
virtual INLINE void consider_update();
INLINE void clear_current_frame();
virtual void update_frame(int frame)=0;
private:
protected:
int _video_width;
int _video_height;
int _last_frame_update;

View File

@ -64,3 +64,32 @@ VideoPage(const OpenCVTexture::VideoPage &copy) :
INLINE OpenCVTexture::VideoPage::
~VideoPage() {
}
////////////////////////////////////////////////////////////////////
// Function: OpenCVTexture::consider_update
// Access: Protected
// Description: Calls update_frame() if the current frame has
// changed.
////////////////////////////////////////////////////////////////////
INLINE void OpenCVTexture::
consider_update() {
int this_frame = ClockObject::get_global_clock()->get_frame_count();
if (this_frame != _last_frame_update) {
int frame = get_frame();
if (_current_frame != frame) {
update_frame(frame);
_current_frame = frame;
} else {
// Loop through the pages to see if there's any camera stream to update.
int max_z = max(_z_size, (int)_pages.size());
for (int z = 0; z < max_z; ++z) {
VideoPage &page = _pages[z];
if (!page._color.is_from_file() || !page._alpha.is_from_file()) {
update_frame(frame, z);
}
}
}
_last_frame_update = this_frame;
}
}

View File

@ -224,9 +224,21 @@ make_texture() {
////////////////////////////////////////////////////////////////////
void OpenCVTexture::
update_frame(int frame) {
grutil_cat.spam() << "OpenCVTexture::update_frame called\n";
int max_z = max(_z_size, (int)_pages.size());
for (int z = 0; z < max_z; ++z) {
update_frame(frame, z);
}
}
////////////////////////////////////////////////////////////////////
// Function: OpenCVTexture::update_frame
// Access: Protected, Virtual
// Description: This variant of update_frame updates the
// indicated page only.
////////////////////////////////////////////////////////////////////
void OpenCVTexture::
update_frame(int frame, int z) {
grutil_cat.spam() << "Updating OpenCVTexture page " << z << "\n";
VideoPage &page = _pages[z];
if (page._color.is_valid() || page._alpha.is_valid()) {
modify_ram_image();
@ -297,7 +309,6 @@ update_frame(int frame) {
}
}
}
}
}
////////////////////////////////////////////////////////////////////

View File

@ -46,10 +46,12 @@ public:
static PT(Texture) make_texture();
protected:
virtual INLINE void consider_update();
virtual PT(Texture) do_make_copy();
void do_assign(const OpenCVTexture &copy);
virtual void update_frame(int frame);
virtual void update_frame(int frame, int z);
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel,