Android opencv and java datatypes

asked 2014-06-16 05:23:09 -0600

cks2k2 gravatar image

hi, i come from a windows c/cpp/c# + intel IPP background, but recently delved into img processing on android + opencv. My question is on opencv data types vis-a-vis java data type.

Colors image are represented in opencv as CV_8UC3. In c/cpp the data type is unsigned char: 0-255. But java has no unsigned type and the closest type that can handle 0-255 is short. What i've been trying to do is create a LUT for gamma correction:

Current code:

public static void gamma(Mat srcMat, Mat dstMat)
{
    double invGamma = 1.0/2.2; // assume gamma = 2.2
    Mat lutMat = new Mat(1, 256, CvType.CV_8UC1);

    int size = (int)(lutMat.total() * lutMat.channels());
    byte[] temp = new byte[size];
    lutMat.get(0, 0, temp);

    for(int j = 0; j < 256; ++j)
    {
        temp[j]== = (byte)(Math.pow((double)j/255.0, invGamma)* 255.0);
    }
    lutMat.put(0, 0, temp);
    Core.LUT(srcMat, lutMat, dstMat);
}

This seems to work (have not fully examined the result), but I am troubled by the cast to java byte. Or does opencv handle this correctly in android?

I tried creating lutMat as CvType.CV_16SC1 and temp as short array but my app will crash after a short while.

edit retag flag offensive close merge delete