Search code examples
copencvwatermarksteganography

compute dct in opencv using cvDCT function


I am using OpenCV 2.1 with vs2010(coding in C). After extracting the blue plane from a rgb image, I applied dct to it to get the transformed matrix.

cvDCT(source,destination,CV_DXT_FORWARD);

It is successfully building, but somehow it is not executing

The error is like "Unhandled exception at 0x75c89617 in freqDomain.exe: Microsoft C++ exception: cv::Exception at memory location 0x001ce35c.."

I think the error is in setting the type of cvarray of output image. is it okay to set it to IPL_DEPTH_8U or should it be float?

This is my code snippet:

int main()
{
    IplImage *input,*output,*b,*g,*r;
    input=cvLoadImage("dolphin.jpg");
    int width,height;
    width=input->width;
    height=input->height;
    b=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
    g=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
    r=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
    cvSplit(input,b,g,r,NULL);
    cvNamedWindow("blue",CV_WINDOW_AUTOSIZE);
    IplImage *b_dct,*g_dct,*r_dct;
    b_dct=cvCreateImage(cvSize(width,height),8,1);
    g_dct=cvCreateImage(cvSize(width,height),8,1);
    r_dct=cvCreateImage(cvSize(width,height),8,1);
    cvDCT(b,b_dct,0);  // doubt??
    cvShowImage("blue",b_dct);

    ...

Solution

  • yeah found the solution :) the problem was with the datatype of source image. it should be float or double.. I used cvConvert function to convert from unsigned int to 32 bit float values.