/home/fwph/code/wurde/modules/visionModule/Operators/ImagePublisher.cpp

Go to the documentation of this file.
00001 #include "ImagePublisher.H"
00002 #include <Logger.H>
00003 #include <string>
00004 #include <opencv/cv.h>
00005 #include <opencv/highgui.h>
00006 
00007 using namespace std;
00008 using namespace WURDE;
00009 using namespace WURDEVision;
00010 
00011 ImagePublisher::ImagePublisher(std::string name) : VisionOperator(name),m_imagesource(name) {
00012        registerSupplier(&m_imagesource);
00013 }
00014 
00015 void ImagePublisher::initOperator() {
00016 
00017        m_state=STATE_RUN;
00018        //       m_format=FORMAT_CHAR_111_RGB;
00019        m_format=FORMAT_CHAR_1_GRAY;
00020 
00021        if(g_globalConfiguration.haveModuleOption(m_name,"format")){
00022               string tmpformat=g_globalConfiguration.getModuleOption(m_name,"format");
00023                std::transform(tmpformat.begin(),tmpformat.end(), tmpformat.begin(), (int (*) (int)) tolower);
00024                
00025                //default is rgb
00026                if(tmpformat=="yuv24"){
00027                       m_format=FORMAT_CHAR_111_YUV24;
00028                }else if(tmpformat=="yuv422"){
00029                       m_format=FORMAT_CHAR_11_YUV422;
00030                }else if(tmpformat=="gray"){
00031                       m_format=FORMAT_CHAR_1_GRAY;
00032                }
00033               
00034                
00035        }
00036 
00037        m_stereo=false;
00038        
00039        m_imagesource.setCompression(COMPRESSION_UNCOMPRESSED);
00040         //m_imagesource.setCompression(COMPRESSION_RLE_LOWQUALITY);
00041        m_imagesource.setFormat(m_format);
00042 
00043        m_imagesource.info.format.setValueAndLock(m_format);
00044        m_imagesource.info.width.setValueAndLock(320);
00045        m_imagesource.info.height.setValueAndLock(240);
00046        m_imagesource.info.compression.setValueAndLock(COMPRESSION_UNCOMPRESSED);
00047        //m_imagesource.info.compression.setValueAndLock(COMPRESSION_RLE_LOWQUALITY);
00048        m_imagesource.info.userChannels.setValueAndLock(-1);
00049        
00050        m_published=false;
00051 
00052 
00053  }
00054 
00055 void ImagePublisher::runOperator(WURDEImage theimage) {
00060        if(!m_published){
00061 #warning Fix special case: supplier not registered, need to publish info
00062               g_debug("Publishing info");
00063               m_imagesource.publishInfo();
00064               m_published=true;
00065        }
00066 
00067        if(m_imagesource.newRequest()){
00068               m_imagesource.getNextRequest();
00069               if(m_imagesource.requests.mType==MESSAGE_PING){
00070                      m_imagesource.publishInfo();
00071               }else{
00072                      g_debug("Trying to publish an image");
00073                      m_imagesource.publishImage(theimage);
00074               }
00075        }
00076 
00077 }
00078 
00079 void ImagePublisher::quitOperator() {
00080 
00081        if(m_imagesource.data.image){
00082               delete [] m_imagesource.data.image;
00083               m_imagesource.data.image=NULL;
00084               m_imagesource.data.imagesize=0;
00085        }
00086 
00087        m_published=false;
00088        m_state=STATE_QUIT;
00089  
00090 }
00091 
00092 extern "C" {
00093 
00094        VisionOperator *ImagePublisher_factory(std::string name) {
00095               return new ImagePublisher(name);
00096        }
00097        
00098        class ImagePublisherProxy { 
00099        public:
00100               ImagePublisherProxy(){
00101                      operatorFactory["ImagePublisher"] = ImagePublisher_factory;
00102               }
00103        };
00104        
00105        ImagePublisherProxy p_imagewriter;
00106 }

Generated on Thu Feb 1 15:31:52 2007 for WURDE by  doxygen 1.5.1