Advertisement
Guest User

ORBtryout

a guest
Mar 22nd, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. package com.example.mysecondopencvapplication;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.os.Environment;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.ImageView;
  10.  
  11. import org.opencv.android.Utils;
  12. import org.opencv.core.Mat;
  13. import org.opencv.core.MatOfByte;
  14. import org.opencv.core.MatOfDMatch;
  15. import org.opencv.core.MatOfKeyPoint;
  16. import org.opencv.core.Scalar;
  17. import org.opencv.features2d.DescriptorExtractor;
  18. import org.opencv.features2d.DescriptorMatcher;
  19. import org.opencv.features2d.FeatureDetector;
  20. import org.opencv.features2d.Features2d;
  21. import org.opencv.highgui.Highgui;
  22.  
  23. import java.io.File;
  24.  
  25.  
  26. public class MainActivity extends AppCompatActivity {
  27.  
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);
  32.     }
  33.  
  34.     void OnCall(View view)
  35.     {
  36.         String filename = "try.png";
  37.         Log.i("Message", "First point");
  38.  
  39.         File root = Environment.getExternalStorageDirectory();
  40.         File file = new File(root, filename);
  41.  
  42.         //Current problem point : emulator dont work well with it & Imread need a path.
  43.  
  44.  
  45.     }
  46.  
  47.    
  48.     void func()
  49.     {
  50.         String firstFileName = "",secondFileName = "";
  51.  
  52.         //read the images.
  53.         /*PROBLEM : emulator is doing problems with this..*/
  54.         Mat img1 = Highgui.imread(firstFileName, Highgui.IMREAD_GRAYSCALE);
  55.         Mat img2 = Highgui.imread(secondFileName, Highgui.IMREAD_GRAYSCALE);
  56.  
  57.         MatOfKeyPoint kp1 = new MatOfKeyPoint();
  58.         MatOfKeyPoint kp2 = new MatOfKeyPoint();
  59.  
  60.         Mat des1 = new Mat();
  61.         Mat des2 = new Mat();
  62.  
  63.         FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
  64.         DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
  65.  
  66.         //Find keypoints
  67.         detector.detect(img1, kp1);
  68.         detector.detect(img2, kp2);
  69.  
  70.         //Find descriptors
  71.         extractor.compute(img1, kp1, des1);
  72.         extractor.compute(img2, kp1, des2);
  73.  
  74.         //Def. of the descriptor matcher
  75.         DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
  76.  
  77.         //Match between the two images
  78.         MatOfDMatch matches = new MatOfDMatch();
  79.         matcher.match(des1, des2, matches);
  80.  
  81.         //Understanding problem : read about it more.
  82.  
  83.         //the results in matches ?
  84.  
  85.         Mat outputImg = new Mat();
  86.         MatOfByte drawnMatches = new MatOfByte();
  87.  
  88.         Features2d.drawMatches(img1, kp1, img2, kp2, matches, outputImg, new Scalar(255,0,0), new Scalar(0,0,255), drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);
  89.  
  90.         Bitmap imageMatched = Bitmap.createBitmap(outputImg.cols(), outputImg.rows(), Bitmap.Config.RGB_565);
  91.         Utils.matToBitmap(outputImg, imageMatched);
  92.  
  93.         //Search what the last lines doing.
  94.     }
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement