找不到原因的报错真的令人抓狂,忙碌了一天一点进展都没有,报错的话也无法运行,连一点成果都看不见,以下是修改后的代码
package com.example.fenzuwork2;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.barcode.BarcodeDetector;
import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.text.TextRecognizer;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.core.CvType;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.DMatch;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point;
import org.opencv.core.KeyPoint;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfFloat;
import org.opencv.features2d.Features2d;
import org.opencv.features2d.ORB;
import org.opencv.features2d.DescriptorMatcher;
import org.opencv.core.MatOfRect;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Core;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.TermCriteria;
import org.opencv.core.CvType;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Size;
import org.opencv.core.CvType;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfInt;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point;

import org.opencv.features2d.DescriptorMatcher;
import org.opencv.features2d.Features2d;
import org.opencv.features2d.ORB;

import org.opencv.highgui.Highgui;

import org.opencv.imgproc.Imgproc;

import org.opencv.android.Utils;

import org.opencv.core.DMatch;

import org.opencv.core.Rect;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private ImageView imageView1, imageView2;
private Mat img1, img2;
private Mat descriptors1, descriptors2;
private MatOfKeyPoint keypoints1, keypoints2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView1 = findViewById(R.id.imageView1);
    imageView2 = findViewById(R.id.imageView2);

    // Load images
    img1 = Highgui.imread("path_to_image1");
    img2 = Highgui.imread("path_to_image2");

    // Create ORB detector
    ORB orb = ORB.create();

    // Detect keypoints and compute descriptors
    keypoints1 = new MatOfKeyPoint();
    descriptors1 = new Mat();
    orb.detectAndCompute(img1, new Mat(), keypoints1, descriptors1);

    keypoints2 = new MatOfKeyPoint();
    descriptors2 = new Mat();
    orb.detectAndCompute(img2, new Mat(), keypoints2, descriptors2);

    // Match descriptors
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors1, descriptors2, matches);

    // Draw matches
    Mat imgMatches = new Mat();
    Features2d.drawMatches(img1, keypoints1, img2, keypoints2, matches, imgMatches);

    // Display images
    Utils.matToBitmap(imgMatches, bitmap);
    imageView1.setImageBitmap(bitmap);
}

}

posted on 2024-06-28 21:55  一点都不难  阅读(22)  评论(0编辑  收藏  举报