How I detect marker using OpenCV for android

asked 2016-06-29 03:07:25 -0600

masehitam gravatar image

updated 2016-06-29 03:22:43 -0600

hi, recently I learned OpenCV for android to make the marker-based augmented reality applications, I found the book Android Application Programming with OpenCV 3 and there are cases where the application successfully seek green image and draw lines on the image. but when I tried to use markers like this, image description the application failed to find an image (not drawing a green line), how do I get an application can find pictures of the markers? here's the code :

public ImageDetectionFilter(final Context context,
        final int referenceImageResourceID) throws IOException {

    // Load the reference image from the app's resources.
    // It is loaded in BGR (blue, green, red) format.
    mReferenceImage = Utils.loadResource(context,
            referenceImageResourceID,
            Imgcodecs.CV_LOAD_IMAGE_COLOR);

    // Create grayscale and RGBA versions of the reference image.
    final Mat referenceImageGray = new Mat();
    Imgproc.cvtColor(mReferenceImage, referenceImageGray,
            Imgproc.COLOR_BGR2GRAY);
    Imgproc.cvtColor(mReferenceImage, mReferenceImage,
            Imgproc.COLOR_BGR2RGBA);

    // Store the reference image's corner coordinates, in pixels.
    mReferenceCorners.put(0, 0,
            new double[] {0.0, 0.0});
    mReferenceCorners.put(1, 0,
            new double[] {referenceImageGray.cols(), 0.0});
    mReferenceCorners.put(2, 0,
            new double[] {referenceImageGray.cols(),
                    referenceImageGray.rows()});
    mReferenceCorners.put(3, 0,
            new double[] {0.0, referenceImageGray.rows()});

    // Detect the reference features and compute their
    // descriptors.
    mFeatureDetector.detect(referenceImageGray,
            mReferenceKeypoints);
    mDescriptorExtractor.compute(referenceImageGray,
            mReferenceKeypoints, mReferenceDescriptors);
}

@Override
public void apply(final Mat src, final Mat dst) {

    // Convert the scene to grayscale.
    Imgproc.cvtColor(src, mGraySrc, Imgproc.COLOR_RGBA2GRAY);

    // Detect the scene features, compute their descriptors,
    // and match the scene descriptors to reference descriptors.
    mFeatureDetector.detect(mGraySrc, mSceneKeypoints);
    mDescriptorExtractor.compute(mGraySrc, mSceneKeypoints,
            mSceneDescriptors);
    mDescriptorMatcher.match(mSceneDescriptors,
            mReferenceDescriptors, mMatches);

    // Attempt to find the target image's corners in the scene.
    findSceneCorners();

    // If the corners have been found, draw an outline around the
    // target image.
    // Else, draw a thumbnail of the target image.
    draw(src, dst);
}

the full source code can be downloaded from here : here

edit retag flag offensive close merge delete

Comments

can you try again in english, please ?

berak gravatar imageberak ( 2016-06-29 03:14:47 -0600 )edit
1

I'm sorry, I'm forget to translate in english

masehitam gravatar imagemasehitam ( 2016-06-29 03:17:21 -0600 )edit

thanks, fine !

berak gravatar imageberak ( 2016-06-29 03:27:45 -0600 )edit

Just a grain of salt to your Project from my side.

I too used the same file as you posted over here in my project before. When I asked about the coding part here, I came to know that the corner's detection is wrong.

In your code // Store the reference image's corner coordinates, in pixels.

Is a wrong approach. I haven't figured it out how to modify it.

WhoAmI gravatar imageWhoAmI ( 2016-06-29 04:01:45 -0600 )edit