-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
72 lines (53 loc) · 2.16 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.example.photodetection;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.aruco.Aruco;
import org.opencv.aruco.Dictionary;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfInt;
import org.opencv.imgproc.Imgproc;
import java.io.IOException;
import java.util.LinkedList;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), , options);
// Log.i("NeverCaresYou", String.valueOf(bitmap.getHeight()));
// Log.i("NeverCaresYou", String.valueOf(bitmap.getWidth()));
if (! OpenCVLoader.initDebug()) {
Log.e("NeverCaresyoU", "init fail");
return;
}
Mat rgba = null;
try {
rgba = Utils.loadResource(MainActivity.this, R.drawable.photo4, CvType.CV_8UC4);
}
catch(IOException e) {
e.printStackTrace();
return;
}
Log.d("NeverCaresyoU", "size" + rgba.size());
Log.i("NeverCaresyoU", String.valueOf(rgba.channels()));
Mat gray = new Mat();
Imgproc.cvtColor(rgba, gray, Imgproc.COLOR_RGBA2GRAY);
Log.i("NeverCaresYou", String.valueOf(gray.channels()));
Dictionary dictionary = Aruco.getPredefinedDictionary(Aruco.DICT_5X5_250);
LinkedList<Mat> corners = new LinkedList<>();
MatOfInt ids = new MatOfInt();
Aruco.detectMarkers(gray, dictionary, corners, ids);
for (int i = 0 ; i < corners.size() ; i++) {
Log.i("NeverCaresyoU", corners.get(i).dump());
}
Log.i("NeverCaresyoU", ids.dump());
}
}