Ask Your Question

Display Keypoints on Image in Android - OpenCV

asked 2014-11-21 11:55:41 -0500

I'm trying display a image with keypoints detected. In my code, i get a list of key points, my i can't display the image on screen. I think that my problem is on converting the image to bitmap from MAT. What i'm doing wrong ?

Here is my code:

Mat teste = new Mat(); Mat mRgba = teste.clone(); Mat outputMat = new Mat();

BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); Bitmap bitmap = drawable.getBitmap(); Utils.bitmapToMat(bitmap, teste);

MatOfKeyPoint myKeyPoints = new MatOfKeyPoint(); FeatureDetector orb = FeatureDetector.create(FeatureDetector.ORB); orb.detect(teste, myKeyPoints);

List<keypoint> referenceKeypointsList = myKeyPoints.toList();

Imgproc.cvtColor(teste, mRgba, Imgproc.COLOR_RGBA2RGB,4); Features2d.drawKeypoints(mRgba, myKeyPoints, mRgba, new Scalar(2,254,255), Features2d.DRAW_RICH_KEYPOINTS); Imgproc.cvtColor(mRgba, outputMat, Imgproc.COLOR_RGB2RGBA); Utils.matToBitmap(outputMat, bitmap);


edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2014-11-26 23:55:05 -0500

rafaoc gravatar image

Look my code. It works fine

int whichDescriptor = siftDescriptor; //freakDescriptor;

        // Features SEARCH
        int detectorType = FeatureDetector.SIFT;
        FeatureDetector detector = FeatureDetector.create(detectorType);

        Mat mask = new Mat();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();
        detector.detect(image, keypoints , mask);               

        if (!detector.empty()){

            // Draw kewpoints
            Mat outputImage = new Mat();
            Scalar color = new Scalar(0, 0, 255); // BGR
            int flags = Features2d.DRAW_RICH_KEYPOINTS; // For each keypoint, the circle around keypoint with keypoint size and orientation will be drawn.
            Features2d.drawKeypoints(image, keypoints, outputImage, color , flags); 
            displayImage(Mat2BufferedImage(outputImage), "Feautures_"+detectorType);

displayImage() and Mat2BufferedImage() are referenced here link1 or link2

edit flag offensive delete link more

Question Tools


Asked: 2014-11-21 11:55:41 -0500

Seen: 1,598 times

Last updated: Nov 26 '14