Search code examples
javaopencvjavacv

JavaCV convert 3 channel IplImage to 4 channel Iplmage


I have tried some methods to create a new 4 channel IplImage from a 3 channel IplImage.I have tried to convert this code from C to JavaCV:

CvMat * src; // your source image
CvMat * dst // your destination image
CvMat * zeros = cvCreateMat(src->cols, src->rows, CV_8UC1);
cvSet(zeros, cvScalar(0, 0, 0, 0));
CvArr * input[] = { src, zeros };
int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
cvMixChannels(input, 2, &dst, 1, from_to, 4);

Taken from here,my conversion is:

    CvMat src; 
    CvMat dst;
    CvMat zeros = cvCreateMat(src.cols(), src.rows(), CV_8UC1);
    cvSet(zeros, cvScalar(0, 0, 0, 0));
    CvArr input[] = { src, zeros };
    int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
    cvMixChannels(input, 2, dst, 1, from_to, 4);

But eclipse says,that the JavaCV mix channels method is this:

The method cvMixChannels(opencv_core.CvArr[], int, opencv_core.CvArr[], int, int[],int) in the type opencv_core is not applicable for the arguments opencv_core.CvArr[], int, opencv_core.CvMat, int, int[], int)

Can anyone help me?

Thanks


Solution

  • Your mistake is that you pass CvMat as first and third arguments to cvMixChannels, while you are expected to pass CvMat[].