mardi 28 juin 2016

Different values from C++ and JAVA using same code

I am translating an android image processing app to ndk. I'm facing the following problem: by logging the some value processed with java/android and others from C++/ndk, I got different values!!

I share with you the java and C++ codes:

Java:

double[] img2 = new double[w*h];
        y1 = new double[w];
        y2 = new double[w];
        for (int j = 0; j < h; j++) {
            for (int n = 2; n < w; ++n) {

                y1[n] = k1 * (img1[j*w+n] + exp(-alpha) * (alpha - 1) * img1[n-1+j*w]) ;

            }

            for(int n = w -3; n>=0; n--){

                y2[n] = k1 *(exp(-alpha)*(alpha+1)*img1[n+1+j*w] - exp(-2*alpha)*img1[n+2+j*w]);
            }

            for (int i = 0; i < w; i++) {
                img2[i+j*w] = y1[i] + y2[i];
            }



        }
        System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ java "+ (int)img2[w/2*h+h/2]);

C++:

double *y1 = new double[w];
    double *y2 = new double[w];
    double *img2 = new double[w * h];
    for (int j = 0; j < h; j++) {
                for (int n = 2; n < w; ++n) {

                    y1[n] = k1 * (img1[j*w+n] + exp(-alpha) * (alpha - 1) * img1[n-1+j*w]);

                }

                for(int n = w -3; n>=0; n--){

                    y2[n] = k1 *(exp(-alpha)*(alpha+1)*img1[n+1+j*w] - exp(-2*alpha)*img1[n+2+j*w]);
                }

                for (int i = 0; i < w; i++) {
                    img2[i+j*w] = y1[i] + y2[i];
                }



            }
    LOGI("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ native %d", (int)img2[w/2*h+h/2]);

The output is:

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ native -2147483648
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ java 13502399

Knowing that I checked that the inputs on both sides(logs gives same values).

Aucun commentaire:

Enregistrer un commentaire