OmniCallback.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@email.it>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #include "OmniCallback.hh"
00021 #include "OmniConfig.hh"
00022 
00023 #include <vector>
00024 
00025 using namespace std;
00026 
00027 static vector<IplImage*> * displayed_images = NULL;
00028 
00029 
00030 //------------------------------------------------------------------------------
00031 // this function will 
00032 // #1 FIX a weird and hidden (?) bug into OpenCV - linux?
00033 // #2 create the vector<IplImage*>  array if it doesn't exist
00034 // #3 add a new image pointer to the vector 
00035 // #4 replace and release the old pointer found on vector[index]. This action is required
00036 // for freeing memory buffers when they aren't used anymore: i.e. a displayed image is
00037 // replaced by another one.
00038 //
00039 
00040 static void os_store_and_replace( IplImage* image, int image_id ) 
00041 {
00042         // does the vector exist?
00043         if ( displayed_images == NULL ) {
00044                 displayed_images = new vector<IplImage*>;
00045                 
00046                 // add a null track_id 0
00047                 displayed_images->push_back( NULL );
00048         }
00049         
00050         int disp_size = (int)displayed_images->size();
00051         if ( disp_size < (image_id +1) ) {
00052                 DEBUG_PRINT ("expanding vector...\n");
00053                 // create new buffers [expand vector]
00054                 for ( int i=0; i < (image_id +1  - disp_size); i++ ) {
00055                         displayed_images->push_back( NULL );
00056                 }
00057         }
00058         
00059         if ( (*displayed_images)[image_id] != NULL ) {
00060 //              cvReleaseImage( &(*displayed_images)[image_id] );
00061         }
00062         (*displayed_images)[image_id] = image;  
00063 }
00064 
00065 
00066 void omnistuff_create_image_context( char* window_id, void* callback_data )
00067 {
00068         DEBUG_PRINT ( "creating window %s\n", window_id );
00069         cvNamedWindow( window_id, 1 );  
00070 }
00071 
00072 void omnistuff_image_do_action( IplImage* image, int track_id, 
00073                                                            char* window_id, void* callback_data )
00074 {
00075 
00076                 
00077 //      DEBUG_PRINT ("displaying image id %d image %d\n", track_id, image );
00078         cvShowImage( window_id, image );
00079         CV_WAIT_KEY( WAIT_KEY_VALUE );
00080         
00081         os_store_and_replace( image, track_id );
00082 //      cvReleaseImage( &image );
00083 }
00084 
00085 void omnistuff_destroy_image_context( char* window_id, void* callback_data )
00086 {
00087         DEBUG_PRINT ( "destroying window %s\n", window_id );
00088         cvDestroyWindow( window_id );   
00089 }
00090 
00091 
00092 
00093 
00094 
00095 
00096 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7