在安卓中显示图像上的关键点 - OpenCV.



>我正在尝试显示检测到关键点的图像。在我的代码中,我得到了一个关键点列表,我的 i 无法在屏幕上显示图像。我认为我的问题是将图像从 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);

看看我的代码。它工作正常

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() 在此处引用链接1或链接2

最新更新