Tuesday, May 15, 2007

Day record - 2007 May 15



convert wxImage to IplImage by "WxImageToIplImage(const wxImage* wx_Image)"
Image processing(as the picture show above)
convert IplImage to wxImage by "IplImageToWxImage(const IplImage* cv_Image)"
Load the wxImage(processed) into my test application and show it.


/*********************************
Convert wxImage to IplImage format.
*********************************/
IplImage* GUIFrame::WxImageToIplImage(const wxImage* wx_Image)
{
if (wx_Image == NULL) return NULL ;
int nWidth = wx_Image->GetWidth () ;
int nHeight = wx_Image->GetHeight () ;
IplImage* cv_Image = NULL ;
cv_Image = cvCreateImage(cvSize(nWidth, nHeight), IPL_DEPTH_8U, 3);
char* pcvImgData = cv_Image->imageData ;
memcpy((void*)pcvImgData, (void*)wx_Image->GetData(), nWidth*nHeight*3) ;
cvCvtColor(cv_Image, cv_Image, CV_BGR2RGB); //the 2nd argument return CvArr* type
return (IplImage*)cv_Image; //must cast to IplImage* type for executing correctly.
}

/*********************************
Convert IplImage to wxImage format.
*********************************/
wxImage* GUIFrame::IplImageToWxImage(const IplImage* cv_Image)
{
if (cv_Image == NULL) return NULL ;
int nWidth = cv_Image->width ;
int nHeight = cv_Image->height;
wxImage* wx_Image = new wxImage() ;
IplImage* cv_ImageBuf = cvCreateImage (cvSize(nWidth, nHeight), IPL_DEPTH_8U, 3) ;
cvCvtColor((CvArr*)cv_Image, cv_ImageBuf, CV_BGR2RGB);
wx_Image->SetData((unsigned char*)cv_ImageBuf->imageData, nWidth, nHeight, false) ;
return wx_Image ;
}

No comments: