Drawing matches using opencv for android

I work with sifting using opencv sdk for Android I am having difficulty drawing matches between two images using

Feature2d.drawMatches ()

whenever I launch the application, it goes through all the steps, but stops when the drawing function is reached.

Here is the full code:

public class MainActivity extends AppCompatActivity {
static {
    System.loadLibrary("opencv_java");
    System.loadLibrary("nonfree");
}

private ImageView imageView;

private FeatureDetector detector = FeatureDetector.create(FeatureDetector.SIFT);
DescriptorExtractor descriptorExtractor=DescriptorExtractor.create(DescriptorExtractor.SIFT);
DescriptorMatcher descriptorMatcher= DescriptorMatcher.create(3);

Bitmap inputImage;
Bitmap inputImage2;
Bitmap out;

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


    if(OpenCVLoader.initDebug()){
        Toast.makeText(this,"Hiii",Toast.LENGTH_SHORT).show();}

    inputImage = BitmapFactory.decodeResource(getResources(), R.drawable.object);
    inputImage2 = BitmapFactory.decodeResource(getResources(), R.drawable.objecttest);
    out = BitmapFactory.decodeResource(getResources(), R.drawable.test);
    imageView = (ImageView) this.findViewById(R.id.imageView);
     sift();
}
public void onResume() {
    super.onResume();
}


public void sift() {

    Mat rgba = new Mat();
    Mat rgba2 = new Mat();
    Mat desc=new Mat();
    Mat desc2=new Mat();
    MatOfDMatch matches=new MatOfDMatch();
    Mat output=new Mat();

    Utils.bitmapToMat(inputImage, rgba);
    Utils.bitmapToMat(inputImage2, rgba2);
    Utils.bitmapToMat(out, output);

    MatOfKeyPoint keyPoints = new MatOfKeyPoint();
    MatOfKeyPoint keyPoints2 = new MatOfKeyPoint();

    Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGBA2GRAY);
    Imgproc.cvtColor(rgba2, rgba2, Imgproc.COLOR_RGBA2GRAY);

    detector.detect(rgba, keyPoints);
    detector.detect(rgba2, keyPoints2);

    descriptorExtractor.compute(rgba,keyPoints,desc);
    descriptorExtractor.compute(rgba2,keyPoints2,desc2);
    descriptorMatcher.match(desc,desc2,matches);

    Features2d.drawMatches(rgba,keyPoints,rgba2,keyPoints2,matches,output);
       Utils.matToBitmap(output, out);
       imageView.setImageBitmap(out);
    }


  }

I also need to know if sift is the best choice for detecting complex objects in real time?

Edit 1: now I notice that I am getting the following errors:

OpenCV error: approval failed (0 <= roi.x & <= roi.width && roi.x + roi.width <= m.cols & <0 <; = roi.y & <= roi.height & roi. y + roi.height <= m.rows)

Fatal signal 11 (SIGSEGV), code 2, error addr 0x12ce08e0 in tid 9971

+4
1

:
, , - (, , , ,
, , , , , )
:

 Features2d.drawMatches(rgba,keyPoints,rgba2,keyPoints2,matches,output);
 Utils.matToBitmap(output, out);
 imageView.setImageBitmap(out);

:

Scalar RED = new Scalar(255,0,0);
Scalar GREEN = new Scalar(0,255,0);
MatOfByte drawnMatches = new MatOfByte();
 Features2d.drawMatches(rgba,keyPoints,rgba2,keyPoints2,matches,output,GREEN, RED,  drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);

Bitmap imageMatched = Bitmap.createBitmap(output.cols(), output.rows(), Bitmap.Config.RGB_565);//need to save bitmap
Utils.matToBitmap(output, imageMatched);
imageView.setImageBitmap(imageMatched);

, , , .

+1

All Articles