openCvAdaptor.cpp
Go to the documentation of this file.
00001 #include "puma2config.h"
00002 #include "openCvAdaptor.h"
00003 
00004 using namespace puma2;
00005 
00006 #ifdef HAVE_OPENCV
00007 
00008 AdaptorOpenCvToPuma2::~AdaptorOpenCvToPuma2()
00009 {
00010   delete iplImage;
00011 }
00012 
00013 #if 0
00014 AdaptorOpenCvToPuma2::AdaptorOpenCvToPuma2(ColorImageRGB8& img)
00015 {
00016     if (img.getWidth() * img.getHeight() == 0) throw "Cannot convert to openCV image";
00017     initIpl((void*)&(img[0][0]), (const char*) "RGB", img.getWidth(), img.getHeight(), 3);
00018     iplImage->widthStep = ((byte*)&(img[1][0])) - ((byte*)&(img[0][0])); /* works for subimages too ! */
00019 }
00020 #endif
00021 
00022 AdaptorOpenCvToPuma2::AdaptorOpenCvToPuma2(const ColorImageRGB8& img)
00023 {
00024     if (img.getWidth() * img.getHeight() == 0) throw "Cannot convert to openCV image";
00025     initIpl((void*)&(img[0][0]), (const char*) "RGB", img.getWidth(), img.getHeight(), 3);
00026     iplImage->widthStep = ((byte*)&(img[1][0])) - ((byte*)&(img[0][0])); /* works for subimages too ! */
00027 }
00028 
00029 #if 0
00030 AdaptorOpenCvToPuma2::AdaptorOpenCvToPuma2(GrayLevelImage8& img)
00031 {
00032     if (img.getWidth() * img.getHeight() == 0) throw "Cannot convert to openCV image";
00033     initIpl((void*)&(img[0][0]), (const char*) "Y", img.getWidth(), img.getHeight(), 1);
00034     iplImage->widthStep = ((byte*)&(img[1][0])) - ((byte*)&(img[0][0])); /* works for subimages too ! */
00035 }
00036 #endif
00037 
00038 AdaptorOpenCvToPuma2::AdaptorOpenCvToPuma2(const GrayLevelImage8& img)
00039 {
00040     if (img.getWidth() * img.getHeight() == 0) throw "Cannot convert to openCV image";
00041     initIpl((void*)&(img[0][0]), (const char*) "Y", img.getWidth(), img.getHeight(), 1);
00042     iplImage->widthStep = ((byte*)&(img[1][0])) - ((byte*)&(img[0][0])); /* works for subimages too ! */
00043 }
00044 
00045 IplImage * AdaptorOpenCvToPuma2::asIplImage()
00046 {
00047   return iplImage;
00048 }
00049 
00050 const IplImage * AdaptorOpenCvToPuma2::asIplImage() const
00051 {
00052   return iplImage;
00053 }
00054 
00055 void AdaptorOpenCvToPuma2::initIpl(void * data, const char * colorModel,
00056   int w, int h, int nChannels)
00057 {
00058    // std::cerr << "Initialize GVI to IPL" << std::endl;
00059    char channelSeq[4] = "Y";  
00060    // char * channelSeq = colorModel;
00061    int width  = w;
00062    int height = h;
00063    // IplImage * ipli = (IplImage*) this;
00064    // IplImage *& ipli = this->iplImage;
00065    IplImage * ipli;
00066    this->iplImage = ipli = new IplImage;
00067 
00068    // IplImage* mask ;
00069    // IplImage* mask = (Cv_iplCreateImageHeader) (
00070    //     1, 0, IPL_DEPTH_1U, "GRAY", "GRAY",
00071    //     IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL,
00072    //     IPL_ALIGN_DWORD, width, height, NULL, NULL,
00073    //      NULL, NULL);
00074 
00075    ipli->nSize     = sizeof(IplImage);
00076    ipli->nChannels = nChannels;
00077    ipli->alphaChannel  = 0;
00078    ipli->depth = IPL_DEPTH_8U;  /* pixel depth in bits: */
00079    ipli->dataOrder = 0;  /* 0 - interleaved , 1 - separate color channels. */
00080    ipli->origin = 0;        /* 0 - top-left origin */
00081    ipli->width     = width;
00082    ipli->height    = height;
00083    ipli->align     = IPL_ALIGN_QWORD; /* Alignment of image rows (4 or 8).  */
00084    ipli->ID        = 0; /* version (=0)*/
00085    ipli->roi = NULL;  /* image ROI. if NULL, the whole image is selected */
00086    ipli->maskROI = NULL ; /* must be NULL */
00087    ipli->imageId = NULL ;     /* ditto */
00088    ipli->tileInfo = NULL ; /* ditto */
00089 
00090   *((int*)(*ipli).colorModel) = *((int*) colorModel);
00091   *((int*)(*ipli).channelSeq) = *((int*) channelSeq);
00092 
00093     ipli->imageSize = ipli->width * ipli->height * nChannels ;
00094     ipli->imageData = (char*) data ;  /* pointer to aligned image data */
00095     ipli->imageDataOrigin = ipli->imageData;
00096     ipli->imageDataOrigin = NULL;
00097 
00098     // this code works for normal images only, not for subimages:
00099     ipli->widthStep = ipli->width*nChannels;   /* size of aligned image row in bytes */
00100 }
00101 
00102 #endif


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43