Ask Your Question
0

Open CV on Java, Mask after findHomography()

asked 2014-12-01 14:39:46 -0600

Sokol gravatar image

updated 2014-12-02 03:12:28 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-07 07:11:06 -0600

hayley gravatar image

Hi Marcin,

I know this post is a bit old but I wanted to post my feedback in case others like myself come across this page...

The reason why you are seeing so many matches in the image, is because your mask is not filtered through ransac. Instead, your current mask is displaying your matOfDMatch list, which is the entire list of possible matches between all of the detected features from the two images.

Hope it helps!

edit flag offensive delete link more

Comments

This question very old.

monxarat gravatar imagemonxarat ( 2018-09-07 08:30:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-12-01 14:39:46 -0600

Seen: 1,029 times

Last updated: Sep 07 '18