【问题标题】:Display Keypoints on Image in Android - OpenCV在 Android 中的图像上显示关键点 - OpenCV
【发布时间】:2015-01-19 20:31:18
【问题描述】:

我正在尝试显示检测到关键点的图像。在我的代码中,我得到了一个关键点列表,我无法在屏幕上显示图像。我认为我的问题是将图像从 MAT 转换为位图。 我做错了什么?

这是我的代码:

    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);

    imageView.setImageBitmap(bitmap);

【问题讨论】:

  • 顺便说一句:mRgba 应该称为 mRgb,因为根据您对 cvtColor 的使用,它不包含 alpha 通道。而且我不确定 Imgproc.COLOR_RGBA2RGB,4 会导致什么 - 可能会删除 4 因为你想要一个 RGB 图像,即三个通道
  • 这4个类似Features2d.DRAW_RICH_KEYPOINTS。
  • 变量名错误。我的结果就像一个白屏,只是它。我不明白为什么,我喜欢这样:Follow the link
  • 在 cvtColor 调用中省略 4 会发生什么?
  • 同样,如果我离开4,当我想显示关键点时,我的图像是全白的,我只是看到一个白屏。

标签: java android opencv feature-detection keypoint


【解决方案1】:

看看我的代码。效果很好

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() 和 Mat2BufferedImage() 在这里被引用 link1link2

【讨论】:

    猜你喜欢
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2015-05-26
    • 2013-10-31
    相关资源
    最近更新 更多