00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef HIMAGE2IPLIMAGE_H
00020 #define HIMAGE2IPLIMAGE_H
00021
00025 #include <Halcon.h>
00026
00027
00028
00029
00030
00031 template<class type> IplImage* CPYIMG2CV(Hlong** himg, CvSize size, INT depth, INT channels, INT width, INT height)
00032 {
00033 IplImage* iplimg;
00034 type* pointer[3];
00035 int pixelItLines = 1;
00036 int pixelItColumns = 1;
00037 int channelIt = 0;
00038 iplimg = cvCreateImage(size, depth, channels);
00039 if(channels == 1 && (sizeof(type) * width * height) == iplimg->imageSize)
00040 {
00041 memcpy(iplimg->imageData, (void*)himg[0], sizeof(type) * width * height);
00042 }
00043 else
00044 {
00045 for (channelIt = 0; channelIt < channels; channelIt++)
00046 pointer[channelIt] = (type*)himg[channelIt];
00047 for (pixelItLines = 0; pixelItLines < height ;pixelItLines++ )
00048 {
00049 for (pixelItColumns = 0;pixelItColumns < width; pixelItColumns++)
00050 {
00051 CvScalar csv;
00052 for (channelIt = 0; channelIt < channels; channelIt++)
00053 {
00054 csv.val[(channels-1) - channelIt] = pointer[channelIt][pixelItLines * width + pixelItColumns];
00055 }
00056 cvSet2D(iplimg,pixelItLines,pixelItColumns,csv);
00057 }
00058 }
00059 }
00060 return iplimg;
00061 }
00062
00063
00064 #define CPYIMG_STRUCT2CV(depth, channels, width, height, type) \
00065 { \
00066 int pixelItLines = 1; \
00067 int pixelItColumns = 1; \
00068 int channelIt = 0; \
00069 iplimg = cvCreateImage(size, depth, channels); \
00070 for (pixelItLines = 0; pixelItLines < height ;pixelItLines++ ) \
00071 { \
00072 for (pixelItColumns = 0;pixelItColumns < width; pixelItColumns++) \
00073 { \
00074 CvScalar csv; \
00075 for(channelIt = 0; channelIt < channels; channelIt++) \
00076 csv.val[(channels - 1) - channelIt] = himg[channelIt][pixelItLines * width + pixelItColumns]; \
00077 cvSet2D(iplimg,pixelItLines,pixelItColumns,csv); \
00078 } \
00079 } \
00080 }
00081
00082
00083 #define CPYIMG_COMPLEX2CV(depth, channels, width, height, type) \
00084 { \
00085 int pixelItLines = 1; \
00086 int pixelItColumns = 1; \
00087 int channelIt = 0; \
00088 iplimg = cvCreateImage(size, depth, channels); \
00089 for (pixelItLines = 0; pixelItLines < height ;pixelItLines++ ) \
00090 { \
00091 for (pixelItColumns = 0;pixelItColumns < width; pixelItColumns++) \
00092 { \
00093 CvScalar csv; \
00094 for(channelIt = 0; channelIt < channels / 2; channelIt++) \
00095 { \
00096 csv.val[((channels/2- 1) - channelIt) * 2 ] = himg[channelIt][pixelItLines * width + pixelItColumns]; \
00097 csv.val[((channels/2- 1) - channelIt) * 2 + 1] = himg[channelIt][pixelItLines * width + pixelItColumns]; \
00098 } \
00099 cvSet2D(iplimg,pixelItLines,pixelItColumns,csv); \
00100 } \
00101 } \
00102 }
00103
00104
00114 IplImage *HImage2IplImage(Hlong** himg, INT channels, INT width, INT height, INT type)
00115 {
00116 IplImage* iplimg;
00117 CvSize size;
00118 size.width = width;
00119 size.height = height;
00120 if(channels > 3)
00121 channels = 3;
00122
00123 switch(type)
00124 {
00125 case BYTE_IMAGE:
00126
00127 iplimg = CPYIMG2CV<HBYTE>(himg,size, IPL_DEPTH_8U, channels, width, height);
00128 break;
00129 case INT4_IMAGE:
00130
00131 iplimg = CPYIMG2CV<INT4>(himg,size, IPL_DEPTH_32S, channels, width, height);
00132 break;
00133 case FLOAT_IMAGE:
00134
00135 iplimg = CPYIMG2CV<float>(himg,size, IPL_DEPTH_32F, channels, width, height);
00136
00137
00138 break;
00139 case DIR_IMAGE:
00140 iplimg = CPYIMG2CV<HBYTE>(himg,size, IPL_DEPTH_8U, channels, width, height);
00141 break;
00142 case CYCLIC_IMAGE:
00143
00144 iplimg = CPYIMG2CV<HBYTE>(himg,size, IPL_DEPTH_8U, channels, width, height);
00145 break;
00146 case INT1_IMAGE:
00147
00148 iplimg = CPYIMG2CV<INT1>(himg,size, IPL_DEPTH_8S, channels, width, height);
00149 break;
00150 case COMPLEX_IMAGE:
00151 CPYIMG_COMPLEX2CV(IPL_DEPTH_32F, channels * 2, width, height, float*)
00152 break;
00153 case INT2_IMAGE:
00154
00155 CPYIMG_STRUCT2CV(IPL_DEPTH_16S, channels, width, height, HInt2Pixel)
00156 break;
00157 case UINT2_IMAGE:
00158
00159 CPYIMG_STRUCT2CV(IPL_DEPTH_16U, channels, width, height, HUInt2Pixel)
00160 break;
00161 }
00162 return iplimg;
00163 }
00164
00165
00166 #endif