title: drawing matches using opencv for android
body: <p>I'm working with sift using opencv sdk for android<br />
  I'm facing difficulties in drawing matches between two images using the</p>
  <blockquote>
  <p>Feature2d.drawMatches()</p>
  </blockquote>
  <p>whenever I run the app it goes through all the steps but stopped when reaching the draw function.</p>
  <p>Here's the full code:</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  static {
      System.loadLibrary(&quot;opencv_java&quot;);
      System.loadLibrary(&quot;nonfree&quot;);
  }
  
  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,&quot;Hiii&quot;,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);
      }
  
  
    }
  </code></pre>
  <p><em>I also need to know whether sift is the best choice for the use of detecting complicated objects in real time?</em></p>
  <p><em>Edit 1</em>: I notice now that I'm getting the following errors</p>
  <blockquote>
  <p>OpenCV Error: Assertion failed (0 &lt;= roi.x &amp;&amp; 0 &lt;= roi.width &amp;&amp; roi.x + roi.width &lt;= m.cols &amp;&amp; 0 &lt;= roi.y &amp;&amp; 0 &lt;= roi.height &amp;&amp; roi.y + roi.height &lt;= m.rows)</p>
  <p>Fatal signal 11 (SIGSEGV), code 2, fault addr 0x12ce08e0 in tid 9971</p>
  </blockquote>