質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,300 +26,12 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
###現在のソース
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
```java
|
34
|
-
|
35
|
-
import java.awt.Graphics;
|
36
|
-
|
37
|
-
import java.awt.image.BufferedImage;
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
import javax.swing.JFrame;
|
42
|
-
|
43
|
-
import javax.swing.JPanel;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
import org.opencv.core.Core;
|
48
|
-
|
49
|
-
import org.opencv.core.DMatch;
|
50
|
-
|
51
|
-
import org.opencv.core.Mat;
|
52
|
-
|
53
|
-
import org.opencv.core.MatOfDMatch;
|
54
|
-
|
55
|
-
import org.opencv.core.MatOfKeyPoint;
|
56
|
-
|
57
|
-
import org.opencv.features2d.DescriptorExtractor;
|
58
|
-
|
59
|
-
import org.opencv.features2d.DescriptorMatcher;
|
60
|
-
|
61
|
-
import org.opencv.features2d.FeatureDetector;
|
62
|
-
|
63
|
-
import org.opencv.features2d.Features2d;
|
64
|
-
|
65
|
-
import org.opencv.imgcodecs.Imgcodecs;
|
66
|
-
|
67
|
-
import org.opencv.imgproc.Imgproc;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
public class AKAZE extends JPanel{
|
74
|
-
|
75
|
-
private static final long serialVersionUID = 1L;
|
76
|
-
|
77
|
-
private BufferedImage image;
|
78
|
-
|
79
|
-
// Create a constructor method
|
80
|
-
|
81
|
-
public AKAZE(){
|
82
|
-
|
83
|
-
super();
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
private BufferedImage getimage(){
|
88
|
-
|
89
|
-
return image;
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
private void setimage(BufferedImage newimage){
|
94
|
-
|
95
|
-
image=newimage;
|
96
|
-
|
97
|
-
return;
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
/**
|
104
|
-
|
105
|
-
* Converts/writes a Mat into a BufferedImage.
|
106
|
-
|
107
|
-
*
|
108
|
-
|
109
|
-
* @param matrix Mat of type CV_8UC3 or CV_8UC1
|
110
|
-
|
111
|
-
* @return BufferedImage of type TYPE_3BYTE_BGR or TYPE_BYTE_GRAY
|
112
|
-
|
113
|
-
*/
|
114
|
-
|
115
|
-
public static BufferedImage matToBufferedImage(Mat matrix) {
|
116
|
-
|
117
|
-
int cols = matrix.cols();
|
118
|
-
|
119
|
-
int rows = matrix.rows();
|
120
|
-
|
121
|
-
int elemSize = (int)matrix.elemSize();
|
122
|
-
|
123
|
-
byte[] data = new byte[cols * rows * elemSize];
|
124
|
-
|
125
|
-
int type;
|
126
|
-
|
127
|
-
matrix.get(0, 0, data);
|
128
|
-
|
129
|
-
switch (matrix.channels()) {
|
130
|
-
|
131
|
-
case 1:
|
132
|
-
|
133
|
-
type = BufferedImage.TYPE_BYTE_GRAY;
|
134
|
-
|
135
|
-
break;
|
136
|
-
|
137
|
-
case 3:
|
138
|
-
|
139
|
-
type = BufferedImage.TYPE_3BYTE_BGR;
|
140
|
-
|
141
|
-
// bgr to rgb
|
142
|
-
|
143
|
-
byte b;
|
144
|
-
|
145
|
-
for(int i=0; i<data.length; i=i+3) {
|
146
|
-
|
147
|
-
b = data[i];
|
148
|
-
|
149
|
-
data[i] = data[i+2];
|
150
|
-
|
151
|
-
data[i+2] = b;
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
break;
|
156
|
-
|
157
|
-
default:
|
158
|
-
|
159
|
-
return null;
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
BufferedImage image2 = new BufferedImage(cols, rows, type);
|
164
|
-
|
165
|
-
image2.getRaster().setDataElements(0, 0, cols, rows, data);
|
166
|
-
|
167
|
-
return image2;
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
public void paintComponent(Graphics g){
|
172
|
-
|
173
|
-
BufferedImage temp=getimage();
|
174
|
-
|
175
|
-
if(temp!=null){
|
176
|
-
|
177
|
-
g.drawImage(temp,10,10,temp.getWidth(),temp.getHeight(), this);
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
public static void main(String[] args) {
|
186
|
-
|
187
|
-
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
188
|
-
|
189
|
-
JFrame frame = new JFrame("BasicPanel");
|
190
|
-
|
191
|
-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
192
|
-
|
193
|
-
frame.setSize(1200,600);
|
194
|
-
|
195
|
-
AKAZE panel = new AKAZE();
|
196
|
-
|
197
|
-
frame.setContentPane(panel);
|
198
|
-
|
199
|
-
frame.setVisible(true);
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
// 比較画像01
|
208
|
-
|
209
|
-
Mat image01 = Imgcodecs.imread("C:/OpenCVtest/2017-09-21 15.25.19.jpg");
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
// 比較画像02
|
214
|
-
|
215
|
-
Mat image02 = Imgcodecs.imread("C:/OpenCVtest/2017-09-21 15.25.21.jpg");
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
Mat grayImage01 = new Mat(image01.rows(), image01.cols(), image01.type());
|
220
|
-
|
221
|
-
Imgproc.cvtColor(image01, grayImage01, Imgproc.COLOR_BGRA2GRAY);
|
222
|
-
|
223
|
-
Core.normalize(grayImage01, grayImage01, 0, 255, Core.NORM_MINMAX);
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
Mat grayImage02 = new Mat(image02.rows(), image02.cols(), image02.type());
|
228
|
-
|
229
|
-
Imgproc.cvtColor(image02, grayImage02, Imgproc.COLOR_BGRA2GRAY);
|
230
|
-
|
231
|
-
Core.normalize(grayImage02, grayImage02, 0, 255, Core.NORM_MINMAX);
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
// ------ AKAZEの処理 ここから ------
|
236
|
-
|
237
|
-
FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.AKAZE);
|
238
|
-
|
239
|
-
DescriptorExtractor siftExtractor = DescriptorExtractor.create(DescriptorExtractor.AKAZE);
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
MatOfKeyPoint keyPoint01 = new MatOfKeyPoint();
|
244
|
-
|
245
|
-
siftDetector.detect(grayImage01, keyPoint01);
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
MatOfKeyPoint keyPoint02 = new MatOfKeyPoint();
|
250
|
-
|
251
|
-
siftDetector.detect(grayImage02, keyPoint02);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
Mat descripters01 = new Mat(image01.rows(), image01.cols(), image01.type());
|
256
|
-
|
257
|
-
siftExtractor.compute(grayImage01, keyPoint01, descripters01);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
Mat descripters02 = new Mat(image02.rows(), image02.cols(), image02.type());
|
262
|
-
|
263
|
-
siftExtractor.compute(grayImage02, keyPoint02, descripters02);
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
MatOfDMatch matchs = new MatOfDMatch();
|
268
|
-
|
269
|
-
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
|
270
|
-
|
271
|
-
matcher.match(descripters01, descripters02, matchs);
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
// 上位50点以外の点を除去する
|
276
|
-
|
277
|
-
int N = 50;
|
278
|
-
|
279
|
-
DMatch[] tmp01 = matchs.toArray();
|
280
|
-
|
281
|
-
DMatch[] tmp02 = new DMatch[N];
|
282
|
-
|
283
|
-
for (int i=0; i<tmp02.length; i++) {
|
284
|
-
|
285
|
-
tmp02[i] = tmp01[i];
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
matchs.fromArray(tmp02);
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
Mat matchedImage = new Mat(image01.rows(), image01.cols()*2, image01.type());
|
296
|
-
|
297
|
-
Features2d.drawMatches(image01, keyPoint01, image02, keyPoint02, matchs, matchedImage);
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
// 出力画像 at AKAZE
|
302
|
-
|
303
|
-
Imgcodecs.imwrite("C:/OpenCVtest/Test.jpg", matchedImage);
|
304
|
-
|
305
|
-
//BufferedImage matchedImage02 = matToBufferedImage(matchedImage);
|
306
|
-
|
307
|
-
// ------ AKAZEの処理 ここまで ------
|
308
|
-
|
309
|
-
return;
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
```
|
320
|
-
|
321
29
|
|
322
30
|
|
323
31
|
###補足
|
324
32
|
|
325
33
|
Windowshは64bitなのですが、IA 32ビットプラットフォームでAMD 64ビット.dllをロードできないといったふうなエラーになりました。
|
34
|
+
|
35
|
+
###追記
|
36
|
+
|
37
|
+
ソースは全く関係なかったのでまぎらわしいので削除しておきます。
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,9 @@
|
|
28
28
|
|
29
29
|
###現在のソース
|
30
30
|
|
31
|
+
```
|
32
|
+
|
31
|
-
```
|
33
|
+
```java
|
32
34
|
|
33
35
|
import java.awt.Graphics;
|
34
36
|
|
@@ -312,6 +314,8 @@
|
|
312
314
|
|
313
315
|
}
|
314
316
|
|
317
|
+
|
318
|
+
|
315
319
|
```
|
316
320
|
|
317
321
|
|