Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Open CV on Java, Mask after findHomography()

I am using opencv in version 2.4.9, using Java JNI. I've downloaded it from open cv official site. In project there is java\x64\opencv_java249.dll included.

I have problem with Features2d.drawMatches() function, it seems that the mask parameter is just ignored.

The mask I have is from Calib3d.findHomography() method and it looks good. Below I attached my code snippet (just minimal working example, I've deleted all unecceseary stuff). In this case, after findHomography() I have masked (size 2530) with only 35 non zero values.

 MatOfByte mask = new MatOfByte();
 Calib3d.findHomography(firstMatOfPoint2f, secondMatOfPoint2f, Calib3d.RANSAC, 1, mask);
 double sum = Stream.of(MatConverter.matToDouble(mask)).mapToDouble(array -> array[0]).sum(); // is 35!

But

 Features2d.drawMatches(
            first, keyPointsFirst,
            second, keyPointsSecond,
            matOfDMatch,
            output,
            Scalar.all(-1), Scalar.all(-1),
            mask, // MASK!!!!!!!!!!!!!!!!
            Features2d.NOT_DRAW_SINGLE_POINTS
    );

draws all (over 2000) matched points.

here you can find ready to use (after image downloaed) code snippet: code snippet on gist.github.com

I used random images from Wikipedia:

first picture from wikipedia, second picture from wikipedia

Here is result I got: enter image description here

As you can see, all matched points are drawn, instead just this according to mask. I am doubt if this is a bug in openCv. Maybe I am using incorrect datatypes? I look into the documentation, but provided exampples are in C or Python. I think that I am following instructions from them perfectly.

Regards, Marcin

Open CV on Java, Mask after findHomography()

I am using opencv in version 2.4.9, using Java JNI. I've downloaded it from open cv official site. In project there is java\x64\opencv_java249.dll included.

I have problem with Features2d.drawMatches() function, it seems that the mask parameter is just ignored.

The mask I have is from Calib3d.findHomography() method and it looks good. Below I attached my code snippet (just minimal working example, I've deleted all unecceseary stuff). In this case, after findHomography() I have masked (size 2530) with only 35 non zero values.

 MatOfByte mask = new MatOfByte();
 Calib3d.findHomography(firstMatOfPoint2f, secondMatOfPoint2f, Calib3d.RANSAC, 1, mask);
 double sum = Stream.of(MatConverter.matToDouble(mask)).mapToDouble(array -> array[0]).sum(); // is 35!

But

 Features2d.drawMatches(
            first, keyPointsFirst,
            second, keyPointsSecond,
            matOfDMatch,
            output,
            Scalar.all(-1), Scalar.all(-1),
            mask, // MASK!!!!!!!!!!!!!!!!
            Features2d.NOT_DRAW_SINGLE_POINTS
    );

draws all (over 2000) matched points.

here you can find ready to use (after image downloaed) code snippet: code snippet on gist.github.com

I used random images from Wikipedia:

first picture from wikipedia, second picture from wikipedia

Here is result I got: enter image description here

As you can see, all matched points are drawn, instead just this according to mask. I am doubt if this is a bug in openCv. Maybe I am using incorrect datatypes? I look into the documentation, but provided exampples are in C or Python. I think that I am following instructions from them perfectly.

Regards, Marcin

Open CV on Java, Mask after findHomography()

I am using opencv in version 2.4.9, using Java JNI. I've downloaded it from open cv official site. In project there is java\x64\opencv_java249.dll included.

I have problem with Features2d.drawMatches() function, it seems that the mask parameter is just ignored.

The mask I have is from Calib3d.findHomography() method and it looks good. Below I attached my code snippet (just minimal working example, I've deleted all unecceseary stuff). In this case, after findHomography() I have masked (size 2530) with only 35 non zero values.

 MatOfByte mask = new MatOfByte();
 Calib3d.findHomography(firstMatOfPoint2f, secondMatOfPoint2f, Calib3d.RANSAC, 1, mask);
 double sum = Stream.of(MatConverter.matToDouble(mask)).mapToDouble(array -> array[0]).sum(); // is 35!

But

 Features2d.drawMatches(
            first, keyPointsFirst,
            second, keyPointsSecond,
            matOfDMatch,
            output,
            Scalar.all(-1), Scalar.all(-1),
            mask, // MASK!!!!!!!!!!!!!!!!
            Features2d.NOT_DRAW_SINGLE_POINTS
    );

draws all (over 2000) matched points.

here you can find ready to use (after image downloaed) code snippet: code snippet on gist.github.com

I used random images from Wikipedia:

first picture from wikipedia, second picture from wikipedia

Here is result I got: enter image description here

As you can see, all matched points are drawn, instead just this according to mask. I am doubt if this is a bug in openCv. Maybe I am using incorrect datatypes? I look into the documentation, but provided exampples are in C or Python. I think that I am following instructions from them perfectly.

Regards, Marcin

-------------- updated at 02.12.2014

I simplified my code snippet, a little bit. Now I tried to set mask explicit.

whole code at: https://gist.github.com/sokolek/2ef24411e9c7259d2f5e

  MatOfByte mask = new MatOfByte(new byte[matOfDMatch.height()]);
        Features2d.drawMatches(
                first, keyPointsFirst,
                second, keyPointsSecond,
                matOfDMatch,
                output,
                Scalar.all(-1), Scalar.all(-1),
                mask, // MASK!!!!!!!!!!!!!!!!
                Features2d.NOT_DRAW_SINGLE_POINTS
        );

mask is filled by zero, but all of the points are still drawn.

Open CV on Java, Mask after findHomography()

I am using opencv in version 2.4.9, using Java JNI. I've downloaded it from open cv official site. In project there is java\x64\opencv_java249.dll included.

I have problem with Features2d.drawMatches() function, it seems that the mask parameter is just ignored.

The mask I have is from Calib3d.findHomography() method and it looks good. Below I attached my code snippet (just minimal working example, I've deleted all unecceseary stuff). In this case, after findHomography() I have masked (size 2530) with only 35 non zero values.

 MatOfByte mask = new MatOfByte();
 Calib3d.findHomography(firstMatOfPoint2f, secondMatOfPoint2f, Calib3d.RANSAC, 1, mask);
 double sum = Stream.of(MatConverter.matToDouble(mask)).mapToDouble(array -> array[0]).sum(); // is 35!

But

 Features2d.drawMatches(
            first, keyPointsFirst,
            second, keyPointsSecond,
            matOfDMatch,
            output,
            Scalar.all(-1), Scalar.all(-1),
            mask, // MASK!!!!!!!!!!!!!!!!
            Features2d.NOT_DRAW_SINGLE_POINTS
    );

draws all (over 2000) matched points.

here you can find ready to use (after image downloaed) code snippet: code snippet on gist.github.com

I used random images from Wikipedia:

first picture from wikipedia, second picture from wikipedia

Here is result I got: enter image description here

As you can see, all matched points are drawn, instead just this according to mask. I am doubt if this is a bug in openCv. Maybe I am using incorrect datatypes? I look into the documentation, but provided exampples are in C or Python. I think that I am following instructions from them perfectly.

Regards, Marcin

-------------- updated at 02.12.2014

I simplified my code snippet, a little bit. Now I tried to set mask explicit.

whole code at: https://gist.github.com/sokolek/2ef24411e9c7259d2f5e

  MatOfByte mask = new MatOfByte(new byte[matOfDMatch.height()]);
        Features2d.drawMatches(
                first, keyPointsFirst,
                second, keyPointsSecond,
                matOfDMatch,
                output,
                Scalar.all(-1), Scalar.all(-1),
                mask, // MASK!!!!!!!!!!!!!!!!
                Features2d.NOT_DRAW_SINGLE_POINTS
        );

mask is filled by zero, but all of the points are still drawn.