Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mysecondopencvapplication;
- import android.graphics.Bitmap;
- import android.os.Environment;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ImageView;
- import org.opencv.android.Utils;
- import org.opencv.core.Mat;
- import org.opencv.core.MatOfByte;
- import org.opencv.core.MatOfDMatch;
- import org.opencv.core.MatOfKeyPoint;
- import org.opencv.core.Scalar;
- import org.opencv.features2d.DescriptorExtractor;
- import org.opencv.features2d.DescriptorMatcher;
- import org.opencv.features2d.FeatureDetector;
- import org.opencv.features2d.Features2d;
- import org.opencv.highgui.Highgui;
- import java.io.File;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- void OnCall(View view)
- {
- String filename = "try.png";
- Log.i("Message", "First point");
- File root = Environment.getExternalStorageDirectory();
- File file = new File(root, filename);
- //Current problem point : emulator dont work well with it & Imread need a path.
- }
- void func()
- {
- String firstFileName = "",secondFileName = "";
- //read the images.
- /*PROBLEM : emulator is doing problems with this..*/
- Mat img1 = Highgui.imread(firstFileName, Highgui.IMREAD_GRAYSCALE);
- Mat img2 = Highgui.imread(secondFileName, Highgui.IMREAD_GRAYSCALE);
- MatOfKeyPoint kp1 = new MatOfKeyPoint();
- MatOfKeyPoint kp2 = new MatOfKeyPoint();
- Mat des1 = new Mat();
- Mat des2 = new Mat();
- FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
- DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
- //Find keypoints
- detector.detect(img1, kp1);
- detector.detect(img2, kp2);
- //Find descriptors
- extractor.compute(img1, kp1, des1);
- extractor.compute(img2, kp1, des2);
- //Def. of the descriptor matcher
- DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
- //Match between the two images
- MatOfDMatch matches = new MatOfDMatch();
- matcher.match(des1, des2, matches);
- //Understanding problem : read about it more.
- //the results in matches ?
- Mat outputImg = new Mat();
- MatOfByte drawnMatches = new MatOfByte();
- Features2d.drawMatches(img1, kp1, img2, kp2, matches, outputImg, new Scalar(255,0,0), new Scalar(0,0,255), drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);
- Bitmap imageMatched = Bitmap.createBitmap(outputImg.cols(), outputImg.rows(), Bitmap.Config.RGB_565);
- Utils.matToBitmap(outputImg, imageMatched);
- //Search what the last lines doing.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement