質問編集履歴
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,152 +12,8 @@
|
|
12
12
|
at java.lang.System.loadLibrary(Unknown Source)
|
13
13
|
at AKAZE.main(AKAZE.java:77)```
|
14
14
|
|
15
|
-
###現在のソース
|
16
|
-
```
|
17
|
-
```java
|
18
|
-
import java.awt.Graphics;
|
19
|
-
import java.awt.image.BufferedImage;
|
20
15
|
|
21
|
-
import javax.swing.JFrame;
|
22
|
-
import javax.swing.JPanel;
|
23
|
-
|
24
|
-
import org.opencv.core.Core;
|
25
|
-
import org.opencv.core.DMatch;
|
26
|
-
import org.opencv.core.Mat;
|
27
|
-
import org.opencv.core.MatOfDMatch;
|
28
|
-
import org.opencv.core.MatOfKeyPoint;
|
29
|
-
import org.opencv.features2d.DescriptorExtractor;
|
30
|
-
import org.opencv.features2d.DescriptorMatcher;
|
31
|
-
import org.opencv.features2d.FeatureDetector;
|
32
|
-
import org.opencv.features2d.Features2d;
|
33
|
-
import org.opencv.imgcodecs.Imgcodecs;
|
34
|
-
import org.opencv.imgproc.Imgproc;
|
35
|
-
|
36
|
-
|
37
|
-
public class AKAZE extends JPanel{
|
38
|
-
private static final long serialVersionUID = 1L;
|
39
|
-
private BufferedImage image;
|
40
|
-
// Create a constructor method
|
41
|
-
public AKAZE(){
|
42
|
-
super();
|
43
|
-
}
|
44
|
-
private BufferedImage getimage(){
|
45
|
-
return image;
|
46
|
-
}
|
47
|
-
private void setimage(BufferedImage newimage){
|
48
|
-
image=newimage;
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Converts/writes a Mat into a BufferedImage.
|
54
|
-
*
|
55
|
-
* @param matrix Mat of type CV_8UC3 or CV_8UC1
|
56
|
-
* @return BufferedImage of type TYPE_3BYTE_BGR or TYPE_BYTE_GRAY
|
57
|
-
*/
|
58
|
-
public static BufferedImage matToBufferedImage(Mat matrix) {
|
59
|
-
int cols = matrix.cols();
|
60
|
-
int rows = matrix.rows();
|
61
|
-
int elemSize = (int)matrix.elemSize();
|
62
|
-
byte[] data = new byte[cols * rows * elemSize];
|
63
|
-
int type;
|
64
|
-
matrix.get(0, 0, data);
|
65
|
-
switch (matrix.channels()) {
|
66
|
-
case 1:
|
67
|
-
type = BufferedImage.TYPE_BYTE_GRAY;
|
68
|
-
break;
|
69
|
-
case 3:
|
70
|
-
type = BufferedImage.TYPE_3BYTE_BGR;
|
71
|
-
// bgr to rgb
|
72
|
-
byte b;
|
73
|
-
for(int i=0; i<data.length; i=i+3) {
|
74
|
-
b = data[i];
|
75
|
-
data[i] = data[i+2];
|
76
|
-
data[i+2] = b;
|
77
|
-
}
|
78
|
-
break;
|
79
|
-
default:
|
80
|
-
return null;
|
81
|
-
}
|
82
|
-
BufferedImage image2 = new BufferedImage(cols, rows, type);
|
83
|
-
image2.getRaster().setDataElements(0, 0, cols, rows, data);
|
84
|
-
return image2;
|
85
|
-
}
|
86
|
-
public void paintComponent(Graphics g){
|
87
|
-
BufferedImage temp=getimage();
|
88
|
-
if(temp!=null){
|
89
|
-
g.drawImage(temp,10,10,temp.getWidth(),temp.getHeight(), this);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
public static void main(String[] args) {
|
94
|
-
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
95
|
-
JFrame frame = new JFrame("BasicPanel");
|
96
|
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
97
|
-
frame.setSize(1200,600);
|
98
|
-
AKAZE panel = new AKAZE();
|
99
|
-
frame.setContentPane(panel);
|
100
|
-
frame.setVisible(true);
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
// 比較画像01
|
105
|
-
Mat image01 = Imgcodecs.imread("C:/OpenCVtest/2017-09-21 15.25.19.jpg");
|
106
|
-
|
107
|
-
// 比較画像02
|
108
|
-
Mat image02 = Imgcodecs.imread("C:/OpenCVtest/2017-09-21 15.25.21.jpg");
|
109
|
-
|
110
|
-
Mat grayImage01 = new Mat(image01.rows(), image01.cols(), image01.type());
|
111
|
-
Imgproc.cvtColor(image01, grayImage01, Imgproc.COLOR_BGRA2GRAY);
|
112
|
-
Core.normalize(grayImage01, grayImage01, 0, 255, Core.NORM_MINMAX);
|
113
|
-
|
114
|
-
Mat grayImage02 = new Mat(image02.rows(), image02.cols(), image02.type());
|
115
|
-
Imgproc.cvtColor(image02, grayImage02, Imgproc.COLOR_BGRA2GRAY);
|
116
|
-
Core.normalize(grayImage02, grayImage02, 0, 255, Core.NORM_MINMAX);
|
117
|
-
|
118
|
-
// ------ AKAZEの処理 ここから ------
|
119
|
-
FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.AKAZE);
|
120
|
-
DescriptorExtractor siftExtractor = DescriptorExtractor.create(DescriptorExtractor.AKAZE);
|
121
|
-
|
122
|
-
MatOfKeyPoint keyPoint01 = new MatOfKeyPoint();
|
123
|
-
siftDetector.detect(grayImage01, keyPoint01);
|
124
|
-
|
125
|
-
MatOfKeyPoint keyPoint02 = new MatOfKeyPoint();
|
126
|
-
siftDetector.detect(grayImage02, keyPoint02);
|
127
|
-
|
128
|
-
Mat descripters01 = new Mat(image01.rows(), image01.cols(), image01.type());
|
129
|
-
siftExtractor.compute(grayImage01, keyPoint01, descripters01);
|
130
|
-
|
131
|
-
Mat descripters02 = new Mat(image02.rows(), image02.cols(), image02.type());
|
132
|
-
siftExtractor.compute(grayImage02, keyPoint02, descripters02);
|
133
|
-
|
134
|
-
MatOfDMatch matchs = new MatOfDMatch();
|
135
|
-
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
|
136
|
-
matcher.match(descripters01, descripters02, matchs);
|
137
|
-
|
138
|
-
// 上位50点以外の点を除去する
|
139
|
-
int N = 50;
|
140
|
-
DMatch[] tmp01 = matchs.toArray();
|
141
|
-
DMatch[] tmp02 = new DMatch[N];
|
142
|
-
for (int i=0; i<tmp02.length; i++) {
|
143
|
-
tmp02[i] = tmp01[i];
|
144
|
-
}
|
145
|
-
matchs.fromArray(tmp02);
|
146
|
-
|
147
|
-
|
148
|
-
Mat matchedImage = new Mat(image01.rows(), image01.cols()*2, image01.type());
|
149
|
-
Features2d.drawMatches(image01, keyPoint01, image02, keyPoint02, matchs, matchedImage);
|
150
|
-
|
151
|
-
// 出力画像 at AKAZE
|
152
|
-
Imgcodecs.imwrite("C:/OpenCVtest/Test.jpg", matchedImage);
|
153
|
-
//BufferedImage matchedImage02 = matToBufferedImage(matchedImage);
|
154
|
-
// ------ AKAZEの処理 ここまで ------
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
|
158
|
-
}
|
159
|
-
|
160
|
-
```
|
161
|
-
|
162
16
|
###補足
|
163
|
-
Windowshは64bitなのですが、IA 32ビットプラットフォームでAMD 64ビット.dllをロードできないといったふうなエラーになりました。
|
17
|
+
Windowshは64bitなのですが、IA 32ビットプラットフォームでAMD 64ビット.dllをロードできないといったふうなエラーになりました。
|
18
|
+
###追記
|
19
|
+
ソースは全く関係なかったのでまぎらわしいので削除しておきます。
|
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,7 +13,8 @@
|
|
13
13
|
at AKAZE.main(AKAZE.java:77)```
|
14
14
|
|
15
15
|
###現在のソース
|
16
|
+
```
|
16
|
-
```
|
17
|
+
```java
|
17
18
|
import java.awt.Graphics;
|
18
19
|
import java.awt.image.BufferedImage;
|
19
20
|
|
@@ -155,6 +156,7 @@
|
|
155
156
|
}
|
156
157
|
|
157
158
|
}
|
159
|
+
|
158
160
|
```
|
159
161
|
|
160
162
|
###補足
|