Convert IplImage to CIppImage

Convert IplImage to CIppImage

 

 Hi~

 I currently use the UIC sample code.

 I want to convert IplImage to CIppImage. and to save *.jpg using the CIppImage type.

 So, i try to convert, but i can't save to *.jpg.

 For example, My sample code is

/////////////////////////////////////////////////////////////////////////////////////////////

    CIppImage         image;
    IM_TYPE           fmtIn;
    IM_TYPE           fmtOut;

    Ipp8u*            buf;

    CStdFileOutput  fo;    
    CMemBuffOutput  mo;

    

    fmtOut = IT_BMP;
    fo.Open(cmdOptions.dst);

    IplImage *img = cvLoadImage(cmdOptions.src,CV_LOAD_IMAGE_GRAYSCALE);
//    cvShowImage("test",cmdOptions.src);

//    cvSaveImage(cmdOptions.dst,img);
    
    image.Width(img->width);
    image.Height(img->height);
    image.Color(IC_GRAY);
    image.Format(IF_FIXED);
    image.Sampling(IS_444);
    image.ComponentOrder(0);
    image.NChannels(img->nChannels);    
    image.Precision(img->depth);
    image.Step(4096);
    image.DataPtr((Ipp8u*)img->imageData);    

    // Encoder
    BaseStream::TPosition pos = 0;  
    size = image.Step()*image.Height()*2;
    buf = (Ipp8u*)ippMalloc((int)size);
    mo.Open(buf, (int)size);
    res = EncodeImage(image, mo, cmdOptions, fmtOut, &encTime);
    mo.Position(pos);    
    mo.Close();
    fo.Write(buf, pos, cnt);
    ippFree(buf);

///////////////////////////////////////////////////////////////////////////////////////////////////////

   Thanks in advance for your help!

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

I am preparing a test workspace for this. Meanwhile could you explain what is "can't save to *jpg"? The output file is broken? Any exception?

Regards,
Sergey

 Hi. Sergey Khlystov 

 Thank you for your response.

 I currently try to convert bmp image type to jpg image type using the IplImage and CIppImage.

 So, first, loading xxx.bmp image using the "cvLoadImage".

 Second, converting IplImage to CIppImage.

 Finally, saving xxx.jpg image using the "CIppImage"

 But, it don't make the xxx.jpg file. Clicking the Image file, i can see the message "The file is empty, you can not display this photo"  

 I think it is a image type converting issue.

 Thanks in advance your help.

I propose do that using the following code:

/////////////////////////////////////////////////////////////////////////////////////////////

	fmtOut = IT_JPEG;
	fo.Open(cmdOptions.dst);
	IplImage *img = cvLoadImage(cmdOptions.src,CV_LOAD_IMAGE_GRAYSCALE);

	image.Attach(img->width, img->height, img->nChannels, img->depth, img->imageData, img->widthStep);
	image.Color(IC_GRAY);

    // Encoder
	BaseStream::TPosition pos = 0;  
	size = image.Step()*image.Height()*2;
	buf = (Ipp8u*)ippMalloc((int)size);
	mo.Open(buf, (int)size);
	res = EncodeImage(image, mo, cmdOptions, fmtOut, &encTime);
	mo.Position(pos);    

    mo.Close();
	fo.Write(buf, pos, cnt);

ippFree(buf);

///////////////////////////////////////////////////////////////////////////////////////////////////////

Should work.

Regards,
Sergey

Leave a Comment

Please sign in to add a comment. Not a member? Join today