回答編集履歴
5
原因を追加
test
CHANGED
@@ -2,7 +2,21 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
[BFMatcher](https://docs.opencv.org/3.4.0/d3/da1/classcv_1_1BFMatcher.html#abe0bb11749b30d97f60d6ade665617bd)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
> Brute-force matcher constructor (obsolete). Please use BFMatcher.create()
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
◇適当和訳
|
14
|
+
|
15
|
+
ブルートフォースマッチャーコンストラクター(廃止)。 BFMatcher.create()を使用してください
|
16
|
+
|
17
|
+
|
18
|
+
|
5
|
-
原因は以下の行です。
|
19
|
+
よって原因は以下の行です。
|
6
20
|
|
7
21
|
```Java
|
8
22
|
|
@@ -22,7 +36,15 @@
|
|
22
36
|
|
23
37
|
```
|
24
38
|
|
39
|
+
もしくは以下のように修正してください。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Java
|
44
|
+
|
25
|
-
|
45
|
+
BFMatcher matcher = BFMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING, true);
|
46
|
+
|
47
|
+
```
|
26
48
|
|
27
49
|
|
28
50
|
|
@@ -208,4 +230,4 @@
|
|
208
230
|
|
209
231
|
◇参考情報
|
210
232
|
|
211
|
-
[cv::BFMatcher::BFMatcher](https://docs.opencv.org/3.
|
233
|
+
[cv::BFMatcher::BFMatcher](https://docs.opencv.org/3.4.0/d3/da1/classcv_1_1BFMatcher.html)
|
4
変更!
test
CHANGED
@@ -66,18 +66,14 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
|
69
|
+
// 元画像1と2を読み込み、Mat配列に格納
|
70
|
-
|
70
|
+
|
71
|
-
Mat im
|
71
|
+
Mat[] images = { loadImage(base_path + "DSC_0021.jpg"), loadImage(base_path + "DSC_0022.jpg") };
|
72
|
-
|
73
|
-
|
74
72
|
|
75
73
|
ORB my_orb = ORB.create(); // 特徴点抽出クラス
|
76
74
|
|
77
75
|
|
78
76
|
|
79
|
-
Mat[] images = { im_src1, im_src2 };
|
80
|
-
|
81
77
|
MatOfKeyPoint[] keypoints = new MatOfKeyPoint[images.length];
|
82
78
|
|
83
79
|
Mat[] descriptors = new Mat[images.length];
|
@@ -148,17 +144,19 @@
|
|
148
144
|
|
149
145
|
public static MatOfDMatch match(Mat[] descriptors) {
|
150
146
|
|
151
|
-
|
152
|
-
|
153
147
|
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
|
154
148
|
|
149
|
+
// DescriptorMatcher matcher = new
|
150
|
+
|
155
|
-
//
|
151
|
+
// BFMatcher(DescriptorMatcher.BRUTEFORCE_HAMMING, true); // 特徴点の対応を調べるクラス
|
156
152
|
|
157
153
|
MatOfDMatch result_matches = new MatOfDMatch(); // マッチング結果保存用行列
|
158
154
|
|
159
155
|
// ※↓の行はC++の公式サンプルには存在しませんが、どこのサンプルに記述されてましたか?
|
160
156
|
|
157
|
+
// result_matches.create(descriptors[0].rows(),
|
158
|
+
|
161
|
-
//
|
159
|
+
// descriptors[0].cols(),descriptors[0].type());
|
162
160
|
|
163
161
|
// 特徴点のマッチング
|
164
162
|
|
@@ -172,8 +170,6 @@
|
|
172
170
|
|
173
171
|
public static void release(Mat[] images) {
|
174
172
|
|
175
|
-
|
176
|
-
|
177
173
|
for (Mat m : images) {
|
178
174
|
|
179
175
|
m.release();
|
3
ソースを改造。
test
CHANGED
@@ -22,22 +22,12 @@
|
|
22
22
|
|
23
23
|
```
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
ように修正すれば、実行時例外が発生しませんが、`BFMatcher`の`crosschek` オプションが`true`になりません。
|
25
|
+
ように修正すれば、実行時例外が発生しませんが、`BFMatcher`の`crosschek` オプションが`true`になりません。ご参考まで。
|
28
|
-
|
29
|
-
取り急ぎ修正案だけでも記述しておきます。
|
30
26
|
|
31
27
|
|
32
28
|
|
33
29
|
```Java
|
34
30
|
|
35
|
-
import java.util.ArrayList;
|
36
|
-
|
37
|
-
import java.util.List;
|
38
|
-
|
39
|
-
|
40
|
-
|
41
31
|
import org.opencv.core.Core;
|
42
32
|
|
43
33
|
import org.opencv.core.Mat;
|
@@ -108,78 +98,88 @@
|
|
108
98
|
|
109
99
|
// 特徴点の対応を調べる
|
110
100
|
|
101
|
+
MatOfDMatch result_matches = match(descriptors);
|
102
|
+
|
103
|
+
Mat outImg = new Mat(); // 結果画像保存用行列
|
104
|
+
|
105
|
+
// 引数を変更
|
106
|
+
|
107
|
+
Features2d.drawMatches(images[0], keypoints[0], images[1], keypoints[1], result_matches, outImg); // 結果をデータ化
|
108
|
+
|
109
|
+
// Features2d.drawMatches(my_descriptors1, my_keypoints1, my_descriptors2,
|
110
|
+
|
111
|
+
// my_keypoints2, result_matches, outImg); //結果をデータ化
|
112
|
+
|
113
|
+
Imgcodecs.imwrite(base_path + "result.jpg", outImg); // 書き込み
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// 後処理
|
118
|
+
|
119
|
+
release(images);
|
120
|
+
|
121
|
+
release(new Mat[] { outImg });
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public static Mat loadImage(String path) {
|
128
|
+
|
129
|
+
// Mat src = Imgcodecs.imread(path);
|
130
|
+
|
131
|
+
// ※グレースケールで読み込むなら以下の行でも。
|
132
|
+
|
133
|
+
Mat src = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
|
134
|
+
|
135
|
+
if (src.empty()) {
|
136
|
+
|
137
|
+
// ファイルが読み込めなかった時
|
138
|
+
|
139
|
+
throw new RuntimeException(path);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
return src;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
public static MatOfDMatch match(Mat[] descriptors) {
|
150
|
+
|
151
|
+
|
152
|
+
|
111
153
|
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
|
112
154
|
|
113
|
-
//
|
155
|
+
//DescriptorMatcher matcher = new BFMatcher(DescriptorMatcher.BRUTEFORCE_HAMMING, true); // 特徴点の対応を調べるクラス
|
114
|
-
|
115
|
-
// true); //特徴点の対応を調べるクラス
|
116
156
|
|
117
157
|
MatOfDMatch result_matches = new MatOfDMatch(); // マッチング結果保存用行列
|
118
158
|
|
119
|
-
//※
|
159
|
+
// ※↓の行はC++の公式サンプルには存在しませんが、どこのサンプルに記述されてましたか?
|
120
|
-
|
160
|
+
|
121
|
-
result_matches.create(descriptors[0].rows(), descriptors[0].cols(),
|
161
|
+
//result_matches.create(descriptors[0].rows(), descriptors[0].cols(),descriptors[0].type());
|
122
|
-
|
162
|
+
|
123
|
-
|
163
|
+
// 特徴点のマッチング
|
124
164
|
|
125
165
|
matcher.match(descriptors[0], descriptors[1], result_matches);
|
126
166
|
|
127
|
-
|
128
|
-
|
129
|
-
Mat outImg = new Mat(); // 結果画像保存用行列
|
130
|
-
|
131
|
-
// 引数を変更
|
132
|
-
|
133
|
-
Features2d.drawMatches(images[0], keypoints[0], images[1], keypoints[1], result_matches, outImg); // 結果をデータ化
|
134
|
-
|
135
|
-
// Features2d.drawMatches(my_descriptors1, my_keypoints1, my_descriptors2,
|
136
|
-
|
137
|
-
// my_keypoints2, result_matches, outImg); //結果をデータ化
|
138
|
-
|
139
|
-
Imgcodecs.imwrite(base_path + "result.jpg", outImg); // 書き込み
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
// 後処理
|
144
|
-
|
145
|
-
re
|
167
|
+
return result_matches;
|
146
|
-
|
147
|
-
|
168
|
+
|
148
|
-
|
149
|
-
}
|
169
|
+
}
|
150
|
-
|
151
|
-
|
152
|
-
|
170
|
+
|
171
|
+
|
172
|
+
|
153
|
-
public static Mat
|
173
|
+
public static void release(Mat[] images) {
|
154
|
-
|
155
|
-
|
174
|
+
|
156
|
-
|
157
|
-
|
175
|
+
|
158
|
-
|
159
|
-
|
176
|
+
|
160
|
-
|
161
|
-
|
177
|
+
for (Mat m : images) {
|
162
|
-
|
163
|
-
|
178
|
+
|
164
|
-
|
165
|
-
|
179
|
+
m.release();
|
166
180
|
|
167
181
|
}
|
168
182
|
|
169
|
-
return src;
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
public static void release(Mat[] images) {
|
176
|
-
|
177
|
-
for (Mat m : images) {
|
178
|
-
|
179
|
-
m.release();
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
183
|
}
|
184
184
|
|
185
185
|
}
|
@@ -188,7 +188,7 @@
|
|
188
188
|
|
189
189
|
```
|
190
190
|
|
191
|
-
ソースを改造しました。
|
191
|
+
勝手ながらソースを改造しました。
|
192
192
|
|
193
193
|
|
194
194
|
|
@@ -206,6 +206,8 @@
|
|
206
206
|
|
207
207
|
5,`imwrite`の書き出しパスを入力ファイルと同一パスに。
|
208
208
|
|
209
|
+
6,`match`メソッドと`release`メソッドを追加
|
210
|
+
|
209
211
|
|
210
212
|
|
211
213
|
◇参考情報
|
2
追記
test
CHANGED
@@ -116,7 +116,7 @@
|
|
116
116
|
|
117
117
|
MatOfDMatch result_matches = new MatOfDMatch(); // マッチング結果保存用行列
|
118
118
|
|
119
|
-
|
119
|
+
//※1 公式のC++サンプルには無いので以下の行は不要だと思いますが、どこに記載されていましたか?
|
120
120
|
|
121
121
|
result_matches.create(descriptors[0].rows(), descriptors[0].cols(), descriptors[0].type()); // 出力先の型を決める?
|
122
122
|
|
@@ -205,3 +205,9 @@
|
|
205
205
|
4,`images`と`keypoints`と`descriptors`は配列で管理するように。
|
206
206
|
|
207
207
|
5,`imwrite`の書き出しパスを入力ファイルと同一パスに。
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
◇参考情報
|
212
|
+
|
213
|
+
[cv::BFMatcher::BFMatcher](https://docs.opencv.org/3.1.0/d3/da1/classcv_1_1BFMatcher.html#abe0bb11749b30d97f60d6ade665617bd)
|
1
追記
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
ように修正すれば、実行時例外が発生しませんが、BFMatcherのcrosschek オプションがtrueになりません。
|
27
|
+
ように修正すれば、実行時例外が発生しませんが、`BFMatcher`の`crosschek` オプションが`true`になりません。
|
28
28
|
|
29
29
|
取り急ぎ修正案だけでも記述しておきます。
|
30
30
|
|
@@ -194,14 +194,14 @@
|
|
194
194
|
|
195
195
|
1,変数は先頭でまとめて宣言せずに適切な値で初期化するように。
|
196
196
|
|
197
|
-
2,ファイルが存在しない時にImgcodecs.imreadの戻り値のMatオブジェクトがemptyで無いかをチェックし例外を発生させるように(loadImageメソッド)。
|
197
|
+
2,ファイルが存在しない時に`Imgcodecs.imread`の戻り値の`Mat`オブジェクトが`empty`で無いかをチェックし例外を発生させるように(`loadImage`メソッド)。
|
198
|
-
|
198
|
+
|
199
|
-
Imgcodecs.imreadは画像が読み取れなかった時に例外を発生せず、後続の処理で例外が発生します。
|
199
|
+
`Imgcodecs.imread`は画像が読み取れなかった時に例外を発生せず、後続の処理で例外が発生します。
|
200
|
-
|
200
|
+
|
201
|
-
3,detectとcomputeを連続して行うなら、Feature2D#detectAndComputeが使えます。
|
201
|
+
3,`detect`と`compute`を連続して行うなら、`Feature2D#detectAndCompute`が使えます。
|
202
202
|
|
203
203
|
→上記ソースでは未対応
|
204
204
|
|
205
|
-
4,imagesとkeypointsとdescriptorsは配列で管理するように。
|
205
|
+
4,`images`と`keypoints`と`descriptors`は配列で管理するように。
|
206
|
-
|
206
|
+
|
207
|
-
5,imwriteの書き出しパスを入力ファイルと同一パスに。
|
207
|
+
5,`imwrite`の書き出しパスを入力ファイルと同一パスに。
|