Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Convert IplImage to CIppImage

Changbu_Jeong
Beginner
390 Views

 

 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!

0 Kudos
3 Replies
Sergey_K_Intel
Employee
390 Views

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?

0 Kudos
Changbu_Jeong
Beginner
390 Views

 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.

0 Kudos
Sergey_K_Intel
Employee
390 Views

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.

0 Kudos
Reply