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]));
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]));
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]));
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]));
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
00059 char channelSeq[4] = "Y";
00060
00061 int width = w;
00062 int height = h;
00063
00064
00065 IplImage * ipli;
00066 this->iplImage = ipli = new IplImage;
00067
00068
00069
00070
00071
00072
00073
00074
00075 ipli->nSize = sizeof(IplImage);
00076 ipli->nChannels = nChannels;
00077 ipli->alphaChannel = 0;
00078 ipli->depth = IPL_DEPTH_8U;
00079 ipli->dataOrder = 0;
00080 ipli->origin = 0;
00081 ipli->width = width;
00082 ipli->height = height;
00083 ipli->align = IPL_ALIGN_QWORD;
00084 ipli->ID = 0;
00085 ipli->roi = NULL;
00086 ipli->maskROI = NULL ;
00087 ipli->imageId = NULL ;
00088 ipli->tileInfo = NULL ;
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 ;
00095 ipli->imageDataOrigin = ipli->imageData;
00096 ipli->imageDataOrigin = NULL;
00097
00098
00099 ipli->widthStep = ipli->width*nChannels;
00100 }
00101
00102 #endif