Changes in version 3.0.0 to 3.1.0 or 3.2.0 in Core.add()

asked 2017-04-21 05:35:28 -0600

Hi,

We develop an Android App that reads camera images and calculates the difference of two subsequent images using the method Core.add():

gryImage.convertTo(gryImage, CvType.CV_16SC1);
refImage.convertTo(refImage, CvType.CV_16SC1, -1);
Core.add(gryImage, refImage, result);

This works fine with opencv version 3.0.0. Now, updating to 3.1.0 or 3.2.0 (both behave the same) the add-method does not write anything to the result matrix.

Note: The add function is already a workaround for the subtract function, which does not work in version 3.0.0, 3.1.0 nor 3.2.0.

This behavior can be reproduced like this:

    public static void testOperations() {
    Mat mat1 = Mat.ones(new Size(10, 10), CvType.CV_16SC1);
    Mat mat2 = Mat.ones(new Size(10, 10), CvType.CV_16SC1);
    Mat mat3;
    double pix;
    /* addition */
    mat3 = Mat.ones(new Size(10, 10), CvType.CV_16SC1);
    Core.add(mat1, mat2, mat3);
    pix = mat3.get(0, 0)[0];
    System.out.println(pix); /* 3.0.0: pix=2 (correct), 3.1.0/3.2.0: pix=1 (wrong) */
    /* subtraction */
    mat3 = Mat.ones(new Size(10, 10), CvType.CV_16SC1);
    Core.subtract(mat1, mat2, mat3);
    pix = mat3.get(0, 0)[0];
    System.out.println(pix); /* 3.0.0: pix=1 (wrong), 3.1.0/3.2.0: pix=1 (wrong) */
}

I would like to have a correct result in either of the two operations in version 3.1.0 or 3.2.0. Can anyone help?

edit retag flag offensive close merge delete

Comments

this answer suggests to use addWeighted

boaz001 gravatar imageboaz001 ( 2017-04-21 10:19:33 -0600 )edit

Yes, this still works. Thanks!

Julia Kurde gravatar imageJulia Kurde ( 2017-04-25 10:36:22 -0600 )edit