2 #include <Base/Common/W32Compat.hh>
3 #include "WrapBias2Ipl.hh"
4 #include <Base/Debug/Error.hh>
5 #include <Base/Debug/DebugSimple.hh>
6 #include <Base/Image/ImageIO.hh>
11 #ifdef BIAS_HAVE_OPENCV
17 #ifdef BIAS_HAVE_OPENCV
22 WrapBias2Ipl::~WrapBias2Ipl(){
34 WrapBias2Ipl::WrapBias2Ipl()
39 ,p_imgIplDestroyable(false)
49 ,p_imgIplDestroyable(false)
51 int result=
Bind(PtrImgBias) ;
56 BIASERR(
"Error on Bind in constructor. result="<<result);
74 BIASERR(
"ImageBase ptr p_src is NULL.");
83 BIASERR(
"Only interleaved images with modulo 4 with are currently supported, sorry.");
94 BIASERR(
"Image width is not multiple of 4 :"<< p_src->
GetWidth()
108 depth=IPL_DEPTH_8S;
break;
110 depth=IPL_DEPTH_8U;
break;
112 depth=IPL_DEPTH_32F;
break;
114 depth=IPL_DEPTH_64F;
break;
116 depth=IPL_DEPTH_16S;
break;
118 depth=IPL_DEPTH_16U;
break;
120 depth=IPL_DEPTH_32S;
break;
124 BIASERR(
"you try to wrap a BIAS unsigned int Image with OpenCV. This format may be unsupported by OpenCV! (JW)");
125 depth=IPL_DEPTH_32S|IPL_DEPTH_SIGN;
127 BIASERR(
"unsupported Storagetype in BIAS image for BIAs->ipl image wrapper. GetStorageType="<<p_src->
GetStorageType() );
132 cvInitImageHeader( p_dest,
148 strcpy( p_dest->colorModel,
"RGB");
149 strcpy( p_dest->channelSeq,
"RGB");
153 strcpy( p_dest->colorModel,
"RGB");
154 strcpy( p_dest->channelSeq,
"BGR");
158 strcpy( p_dest->colorModel,
"RGBA");
159 strcpy( p_dest->channelSeq,
"BGRA");
163 strcpy( p_dest->colorModel,
"RGBA");
164 strcpy( p_dest->channelSeq,
"RGBA");
175 strcpy( p_dest->colorModel,
"GREY");
176 strcpy( p_dest->channelSeq,
"GREY");
179 BIASERR(
"unsupported color model for OpenCV wrapping. "
180 "ChannelSeq may be wrong. "
193 BIASERR(
"IplImage image loading is not supported in llvm/clang built BIAS binaries.");
196 BIASERR(
"IplImage ptr p_src is NULL.");
210 switch (p_src->depth)
239 BIASERR(
"unsupported Ipl Storagetype for Ipl->BIAS wrapper.");
244 if(p_src->width%2 != 0) offset =1;
245 dest.
Init(p_src->width+offset,p_src->height ,p_src->nChannels,dest.
GetStorageType(),
true);
251 if (
string(p_src->colorModel)==
"RGB"){
253 if (
string(p_src->channelSeq)==
"RGB"){
255 }
else if (
string(p_src->channelSeq)==
"BGR"){
258 BIASERR(
"unsupported channelSeq for for OpenCV wrapping of RGB color model");
261 }
else if (
string(p_src->colorModel)==
"RGBA"){
263 if (
string(p_src->channelSeq)==
"RGBA"){
265 }
else if (
string(p_src->channelSeq)==
"BGRA"){
268 BIASERR(
"unsupported channelSeq for for OpenCV wrapping of of RGBA color model");
271 }
else if ((
string(p_src->colorModel)==
"GREY") || (
string(p_src->colorModel)==
"GRAY")) {
275 BIASERR(
"unsupported color model for OpenCV wrapping.");
280 BIASASSERT(p_src!=NULL);
281 BIASASSERT(p_src->origin == IPL_ORIGIN_TL);
305 BIASERR(
"data pointers of bias image and wrapped OpenCV imaeg are inconsisten!!!");
308 BIASERR(
"width is inconsistent!");
311 BIASERR(
"height is inconsistent!");
322 const float & scale )
324 BIASASSERT(src32!=NULL);
325 BIASASSERT(dest8!=NULL);
326 BIASASSERT(src32->width == dest8->width);
327 BIASASSERT(src32->height == dest8->height);
328 BIASASSERT(src32->nChannels==dest8->nChannels);
329 BIASASSERT(src32->depth==32);
330 BIASASSERT(src32->imageData!=NULL);
331 BIASASSERT(dest8->imageData!=NULL);
332 BIASASSERT(scale!=0);
336 float *pSS =
reinterpret_cast<float *
>(src32->imageData);
339 unsigned char *pDD =
reinterpret_cast<unsigned char*
>(dest8->imageData);
340 BIASASSERT(pSS!=NULL);
341 BIASASSERT(pDD!=NULL);
342 const int nX = src32->width * src32->nChannels;
344 for (
int y=0; y<src32->height; y++) {
345 for (
int x=0; x<nX; x++) {
347 pDD[x] = (
unsigned char)( max(0.0f, min(255.0f, scale*pSS[x])) );
350 pSS =
reinterpret_cast<float *
> (&src32->imageData[y*src32->widthStep]);
351 pDD =
reinterpret_cast<unsigned char*
>(&dest8->imageData[y*dest8->widthStep]);
357 return cvWaitKey(delay);
362 const unsigned int & delayMsec,
363 const float & scale)
const
366 return Display(
string( DEFAULT_WrapBias2Ipl_WINNAME ),
true,
false, waitForKey, delayMsec, scale);
370 const bool & autoresize,
371 const bool & moveToTopLeft,
372 const bool & waitForKey,
373 const unsigned int & delayMsec,
375 const bool & allowAlphaWindow
378 std::string name(DestWin);
391 const bool & autoresize,
392 const bool & moveToTopLeft,
393 const bool & waitForKey,
394 const unsigned int & delayMsec,
396 const bool & allowAlphaWindow
399 return Display(this->
p_imgIpl, DestWin, autoresize, moveToTopLeft, waitForKey, delayMsec, scale, allowAlphaWindow);
406 const std::string & DestWin,
407 const bool & autoresize,
408 const bool & moveToTopLeft,
409 const bool & waitForKey,
410 const unsigned int & delayMsec,
412 const bool & allowAlphaWindow
419 if (img->width==0 || img->height==0) {
420 BIASERR(
"empty image of dim "<<img->width<<
"x"<<img->height);
426 if (autoresize) winflags = winflags | CV_WINDOW_AUTOSIZE;
427 cvNamedWindow(DestWin.c_str(), winflags);
428 if (moveToTopLeft) cvMoveWindow(DestWin.c_str(), 0,0);
433 if (strcmp(img->channelSeq,
"BGR")==0)
436 cvShowImage(DestWin.c_str(), img);
437 }
else if (strcmp(img->channelSeq,
"RGB")==0) {
439 IplImage *p_swapped=NULL;
441 p_swapped = cvCreateImage( cvSize(img->width, img->height),
444 cvConvertImage( img, p_swapped, CV_CVTIMG_SWAP_RB);
445 cvShowImage(DestWin.c_str(), p_swapped);
446 cvReleaseImage(&p_swapped);
447 }
else if ((strcmp(img->channelSeq,
"GREY")==0) || (strcmp(img->channelSeq,
"GRAY")==0)) {
448 cvShowImage(DestWin.c_str(), img);
449 }
else if (strcmp(img->channelSeq,
"RGBA")==0) {
450 if (allowAlphaWindow)
453 IplImage *p_alpha=cvCreateImage( cvSize(img->width, img->height),
457 for (
int i=0; i<((p_alpha->width) * (p_alpha->height)); i++){
458 p_alpha->imageData[i] = img->imageData[4*i+3];
460 const string alphaWin = DestWin+
"_alpha";
461 cvNamedWindow(alphaWin.c_str(), 1);
462 cvShowImage(alphaWin.c_str(), p_alpha);
463 cvReleaseImage(&p_alpha);
467 cvShowImage(DestWin.c_str(), img);
469 BIASERR(
"Sorry, colorChannelSeq/colorModel unsupported. "<<endl
470 <<
"bitdepth="<<img->depth<<
" channelseq="<<img->channelSeq <<endl
471 <<
"Please complete switch. Trying to display anyhow.");
472 cvShowImage(DestWin.c_str(), img);
479 IplImage *p_8bit=NULL;
480 p_8bit = cvCreateImage( cvSize(img->width, img->height),
485 memcpy(p_8bit->channelSeq, img->channelSeq, 4);
491 if (strcmp(p_8bit->channelSeq,
"BGR")==0)
494 cvShowImage(DestWin.c_str(), p_8bit);
495 }
else if (strcmp(p_8bit->channelSeq,
"RGB")==0) {
497 IplImage *p_swapped=NULL;
499 p_swapped = cvCreateImage( cvSize(p_8bit->width, p_8bit->height),
502 cvConvertImage( p_8bit, p_swapped, CV_CVTIMG_SWAP_RB);
503 cvShowImage(DestWin.c_str(), p_swapped);
504 cvReleaseImage(&p_swapped);
505 }
else if ((strcmp(p_8bit->channelSeq,
"GREY")==0) || (strcmp(p_8bit->channelSeq,
"GRAY")==0)) {
506 cvShowImage(DestWin.c_str(), p_8bit);
508 BIASERR(
"Sorry, colorChannelSeq/colorModel/depth unsupported. "<<endl
509 <<
"bitdepth="<<img->depth<<
" channelseq="<<img->channelSeq <<endl
510 <<
"Please complete switch. Trying to display anyhow.");
511 cvShowImage(DestWin.c_str(), p_8bit);
516 BIASERR(
"Sorry, colorChannelSeq/colorModel/depth unsupported. "<<endl
517 <<
"bitdepth="<<img->depth<<
" channelseq="<<img->channelSeq <<endl
518 <<
"Please complete switch. Trying to display anyhow.");
519 cvShowImage(DestWin.c_str(), img);
536 cvDestroyAllWindows();
541 cvDestroyWindow( name );
551 const unsigned int width,
552 const unsigned int height )
554 cvResizeWindow( name, width, height );
558 const unsigned int width,
559 const unsigned int height )
567 cvMoveWindow( name, newX, newY );
578 cvNamedWindow(name, flags);
583 cvNamedWindow(name.c_str(), flags);
588 #endif // BIAS_HAVE_OPENCV
Bayer_GRBG, 1 channel RGB image Bayer tile.
(16bit) unsigned integer image storage type
static void MoveWindow(const char *name, const int newX, const int newY)
enum EStorageType StorageType_
the storage type in a pixel channel
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
bool IsInterleaved() const
(8bit) signed char image storage type
void SetColorModel(EColorModel Model)
Bayer_RGGB, 1 channel RGB image Bayer tile.
static void DestroyAllWindows()
wrapper for CV destroiing all HighGUI windows JW
static void ResizeWindow(const char *name, const unsigned int width, const unsigned int height)
double image storage type
static int CreateBiasImageCopy(const IplImage *p_src, BIAS::ImageBase &dest)
helper function to create a copy (!) BIAS image from a master Ipl image Data area is NOT shared but...
unsigned int GetWidth() const
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
invalid not set image storage type
(16bit) signed integer image storage type
color values, 3 channels, order: blue,green,red
Bayer_BGGR, 1 channel RGB image Bayer tile.
const void * GetImageData() const
Bayer_GBRG, 1 channel RGB image Bayer tile.
static void NamedWindow(const char *name, const int flags=1)
static void ConvertIPL32to8(const IplImage *src32, IplImage *dest8, const float &scale=DEFAULT_32to8_scale)
32 bit float to displayable 8 bit conversion Both images should be pre-initilaized to equal size and...
static int CreateIplImageShared(const BIAS::ImageBase *p_src, IplImage *&p_dest)
helper function to create a slave ipl image which shares the data area with the master ref...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
unsigned int GetHeight() const
RGBA, 4 channels, order: red,green,blue,alpha.
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
enum EColorModel GetColorModel() const
const BIAS::ImageBase * p_imgBias
(32bit) signed integer image storage type
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
static void DestroyWindow(const char *name)
This is the base class for images in BIAS.
static int Display(const IplImage *img, const std::string &DestWin, const bool &autoresize, const bool &moveToTopLeft, const bool &waitForKey, const unsigned int &delayMsec, const float &scale=DEFAULT_32to8_scale, const bool &allowAlphaWindow=ALLOW_ALPHA_WIN_DEFAULT)
Display img as simple popup window.
BGRA color values, 4 channels, order: blue,green,red,alpha.
(32bit) unsigned integer image storage type
static int WaitKey(const unsigned int &delay=0)
wrapper for cvWaitKey
int Bind(const BIAS::ImageBase *p_src)
create the internal IPL image which shares the data area with the src Bias image. ...