質問編集履歴
5
コード更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -242,7 +242,7 @@
|
|
242
242
|
|
243
243
|
|
244
244
|
|
245
|
-
//変更1(this追加)
|
245
|
+
//変更1(this追加) 2016/12/14
|
246
246
|
|
247
247
|
TemplateMatching.main(dst, temp, "c:/Users/Public/Pictures/dst.png", this);
|
248
248
|
|
@@ -326,7 +326,7 @@
|
|
326
326
|
|
327
327
|
```TemplateMatching.java
|
328
328
|
|
329
|
-
//変更点2 (MainActivity actを追加)
|
329
|
+
//変更点2 (MainActivity actを追加)2016/12/14
|
330
330
|
|
331
331
|
|
332
332
|
|
@@ -374,8 +374,6 @@
|
|
374
374
|
|
375
375
|
|
376
376
|
|
377
|
-
private SurfaceHolder m_surfaceHolder;
|
378
|
-
|
379
377
|
|
380
378
|
|
381
379
|
public MatchingDemo() {
|
@@ -384,6 +382,8 @@
|
|
384
382
|
|
385
383
|
|
386
384
|
|
385
|
+
//変更点3 (MainActivity actを追加)2016/12/14
|
386
|
+
|
387
387
|
public void run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method, MainActivity act) {
|
388
388
|
|
389
389
|
System.out.println("\nRunning Template Matching");
|
4
現在のプログラムに更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,9 +34,13 @@
|
|
34
34
|
|
35
35
|
int touId = 0;//フラグ変数
|
36
36
|
|
37
|
+
public Mat result;
|
38
|
+
|
37
39
|
Bitmap dst;
|
38
40
|
|
39
|
-
|
41
|
+
|
42
|
+
|
43
|
+
|
40
44
|
|
41
45
|
|
42
46
|
|
@@ -112,17 +116,7 @@
|
|
112
116
|
|
113
117
|
//画像をbitmapに変換
|
114
118
|
|
115
|
-
temp = BitmapFactory.decodeResource(
|
119
|
+
temp = BitmapFactory.decodeResource(getResources(), R.drawable.manzu1);
|
116
|
-
|
117
|
-
mtemp =new Mat(temp.getHeight(), temp.getWidth(), CvType.CV_8UC3);
|
118
|
-
|
119
|
-
//
|
120
|
-
|
121
|
-
Utils.bitmapToMat(temp,mtemp);
|
122
|
-
|
123
|
-
Highgui.imwrite("TempImg.png",mtemp);
|
124
|
-
|
125
|
-
|
126
120
|
|
127
121
|
|
128
122
|
|
@@ -188,8 +182,6 @@
|
|
188
182
|
|
189
183
|
|
190
184
|
|
191
|
-
|
192
|
-
|
193
185
|
@Override
|
194
186
|
|
195
187
|
public void onCameraViewStarted(int width, int height) {
|
@@ -212,7 +204,7 @@
|
|
212
204
|
|
213
205
|
@Override
|
214
206
|
|
215
|
-
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame
|
207
|
+
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
|
216
208
|
|
217
209
|
switch (touId) {
|
218
210
|
|
@@ -228,29 +220,45 @@
|
|
228
220
|
|
229
221
|
mOutputFrame2 = mOutputFrame;
|
230
222
|
|
231
|
-
Log.d("OutputFrame","1 "+mOutputFrame);
|
223
|
+
Log.d("OutputFrame", "1 " + mOutputFrame);
|
232
|
-
|
224
|
+
|
233
|
-
Log.d("OutputFrame2","2 "+mOutputFrame2);
|
225
|
+
Log.d("OutputFrame2", "2 " + mOutputFrame2);
|
226
|
+
|
234
|
-
|
227
|
+
mImageView.setImageBitmap(temp);
|
228
|
+
|
229
|
+
|
230
|
+
|
235
|
-
|
231
|
+
//(Mat型をbitmap型に変換
|
232
|
+
|
236
|
-
|
233
|
+
dst = Bitmap.createBitmap(mOutputFrame2.width(), mOutputFrame2.height(), Bitmap.Config.ARGB_8888);
|
234
|
+
|
237
|
-
|
235
|
+
Utils.matToBitmap(mOutputFrame2, dst);
|
236
|
+
|
238
|
-
|
237
|
+
Log.d("Mat-Bitmap", "完了");
|
238
|
+
|
239
|
-
|
239
|
+
Log.d("dst", "1" + this.dst);
|
240
|
-
|
241
|
-
|
242
|
-
|
240
|
+
|
243
|
-
|
241
|
+
Log.d("temp", "2" + this.temp);
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
242
|
+
|
243
|
+
|
244
|
+
|
249
|
-
|
245
|
+
//変更1(this追加)
|
250
|
-
|
246
|
+
|
251
|
-
|
247
|
+
TemplateMatching.main(dst, temp, "c:/Users/Public/Pictures/dst.png", this);
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
252
|
-
|
253
|
+
//アプリが落ちる
|
254
|
+
|
253
|
-
|
255
|
+
ImageView imageView = (ImageView) findViewById(R.id.image);
|
256
|
+
|
257
|
+
imageView.setImageBitmap(dst);
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
touId = 2;
|
254
262
|
|
255
263
|
break;
|
256
264
|
|
@@ -308,6 +316,8 @@
|
|
308
316
|
|
309
317
|
}
|
310
318
|
|
319
|
+
}
|
320
|
+
|
311
321
|
|
312
322
|
|
313
323
|
```
|
@@ -316,40 +326,34 @@
|
|
316
326
|
|
317
327
|
```TemplateMatching.java
|
318
328
|
|
329
|
+
//変更点2 (MainActivity actを追加)
|
330
|
+
|
331
|
+
|
332
|
+
|
319
333
|
public class TemplateMatching {
|
320
334
|
|
321
|
-
|
335
|
+
public static void main(Bitmap dst, Bitmap temp, String outFile, MainActivity act) {
|
322
|
-
|
336
|
+
|
323
|
-
|
337
|
+
Log.d("tem_match","Library_start");
|
324
|
-
|
338
|
+
|
325
|
-
|
339
|
+
try{
|
326
|
-
|
340
|
+
|
327
|
-
|
341
|
+
System.loadLibrary("opencv_java");
|
328
|
-
|
342
|
+
|
329
|
-
|
343
|
+
Log.d("tem_match","Library_end");
|
330
|
-
|
344
|
+
|
331
|
-
|
345
|
+
}catch(Exception e){
|
332
|
-
|
346
|
+
|
333
|
-
|
347
|
+
Log.d("tem_match","Library_error");
|
334
|
-
|
348
|
+
|
335
|
-
|
349
|
+
}
|
336
|
-
|
337
|
-
|
350
|
+
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
351
|
+
new MatchingDemo().run(dst, temp, outFile, Imgproc.TM_CCOEFF, act);
|
342
|
-
|
343
|
-
|
352
|
+
|
344
|
-
|
345
|
-
|
353
|
+
|
346
|
-
|
347
|
-
}
|
348
354
|
|
349
355
|
}
|
350
356
|
|
351
|
-
|
352
|
-
|
353
357
|
```
|
354
358
|
|
355
359
|
|
@@ -366,27 +370,33 @@
|
|
366
370
|
|
367
371
|
private Mat result;
|
368
372
|
|
373
|
+
public Bitmap dst2;
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
private SurfaceHolder m_surfaceHolder;
|
378
|
+
|
379
|
+
|
380
|
+
|
369
381
|
public MatchingDemo() {
|
370
382
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
}
|
383
|
+
}
|
376
|
-
|
384
|
+
|
385
|
+
|
386
|
+
|
377
|
-
public void run(
|
387
|
+
public void run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method, MainActivity act) {
|
378
388
|
|
379
389
|
System.out.println("\nRunning Template Matching");
|
380
390
|
|
381
391
|
|
382
392
|
|
383
|
-
|
393
|
+
img = new Mat(inFile.getHeight(), inFile.getWidth(), CvType.CV_8UC1);
|
394
|
+
|
384
|
-
|
395
|
+
templ = new Mat(templateFile.getHeight(), templateFile.getWidth(), CvType.CV_8UC1);
|
396
|
+
|
385
|
-
|
397
|
+
Utils.bitmapToMat(inFile, img);
|
386
|
-
|
398
|
+
|
387
|
-
|
399
|
+
Utils.bitmapToMat(templateFile, templ);
|
388
|
-
|
389
|
-
|
390
400
|
|
391
401
|
|
392
402
|
|
@@ -400,27 +410,25 @@
|
|
400
410
|
|
401
411
|
|
402
412
|
|
413
|
+
|
414
|
+
|
403
|
-
//
|
415
|
+
// 正規化とマッチングを行う
|
404
416
|
|
405
417
|
Imgproc.matchTemplate(img, templ, result, match_method);
|
406
418
|
|
407
|
-
//エラー
|
408
|
-
|
409
419
|
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
|
410
420
|
|
411
421
|
|
412
422
|
|
413
423
|
//閾値が最も高いものを選ぶ
|
414
424
|
|
415
|
-
|
425
|
+
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
|
416
426
|
|
417
427
|
//マッチング時の最大値と最小値を返す
|
418
428
|
|
419
429
|
Point matchLoc;
|
420
430
|
|
421
|
-
// Point matchLoc = new Point();
|
422
|
-
|
423
|
-
|
431
|
+
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
|
424
432
|
|
425
433
|
matchLoc = mmr.minLoc;
|
426
434
|
|
@@ -440,11 +448,13 @@
|
|
440
448
|
|
441
449
|
|
442
450
|
|
443
|
-
//
|
451
|
+
//(Mat型をbitmap型に変換
|
444
|
-
|
452
|
+
|
445
|
-
|
453
|
+
dst2 = Bitmap.createBitmap(img.width(), img.height(), Bitmap.Config.ARGB_8888);
|
446
|
-
|
454
|
+
|
447
|
-
|
455
|
+
Utils.matToBitmap(img, dst2);
|
456
|
+
|
457
|
+
act.dst = dst2;
|
448
458
|
|
449
459
|
|
450
460
|
|
3
現在のコードに変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
```MainActivity.java
|
20
20
|
|
21
|
-
p
|
21
|
+
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
|
22
22
|
|
23
23
|
|
24
24
|
|
@@ -110,21 +110,17 @@
|
|
110
110
|
|
111
111
|
javacameraview.setCvCameraViewListener(this);
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
//画像をbitmapに変換
|
113
|
+
//画像をbitmapに変換
|
116
114
|
|
117
115
|
temp = BitmapFactory.decodeResource( getResources(),R.drawable.manzu1);
|
118
116
|
|
117
|
+
mtemp =new Mat(temp.getHeight(), temp.getWidth(), CvType.CV_8UC3);
|
118
|
+
|
119
|
+
//
|
120
|
+
|
119
121
|
Utils.bitmapToMat(temp,mtemp);
|
120
122
|
|
121
|
-
Highgui.imwrite("TempImg.
|
123
|
+
Highgui.imwrite("TempImg.png",mtemp);
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
124
|
|
129
125
|
|
130
126
|
|
@@ -238,39 +234,23 @@
|
|
238
234
|
|
239
235
|
|
240
236
|
|
241
|
-
|
237
|
+
|
242
|
-
|
243
|
-
|
238
|
+
|
244
|
-
|
245
|
-
|
239
|
+
|
246
|
-
|
247
|
-
|
240
|
+
|
248
|
-
|
249
|
-
|
241
|
+
|
250
|
-
|
251
|
-
|
242
|
+
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
//変更点2
|
256
|
-
|
257
|
-
Highgui.imwrite("dst.
|
243
|
+
Highgui.imwrite("dst.png",mOutputFrame);
|
258
|
-
|
259
|
-
|
244
|
+
|
260
|
-
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
261
|
-
//
|
249
|
+
//moutframeのところにファイルパスを入れる?
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
250
|
+
|
267
|
-
TemplateMatching.main(dst, temp, "C:/Users/ide/AndroidStudioProjects/OpencvCamera/app/src/main/res/drawable/outfile/output.bmp");
|
251
|
+
TemplateMatching.main("dst.png", "temp.png", "C:/Users/ide/AndroidStudioProjects/OpencvCamera/app/src/main/res/drawable/outfile/output.bmp");
|
268
|
-
|
269
|
-
|
252
|
+
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
253
|
+
|
274
254
|
|
275
255
|
break;
|
276
256
|
|
@@ -328,39 +308,145 @@
|
|
328
308
|
|
329
309
|
}
|
330
310
|
|
311
|
+
|
312
|
+
|
313
|
+
```
|
314
|
+
|
315
|
+
TemplateMatching.java
|
316
|
+
|
317
|
+
```TemplateMatching.java
|
318
|
+
|
319
|
+
public class TemplateMatching {
|
320
|
+
|
321
|
+
public static void main(String inFile, String templateFile, String outFile) {
|
322
|
+
|
323
|
+
Log.d("tem_match","Library_start");
|
324
|
+
|
325
|
+
try{
|
326
|
+
|
327
|
+
System.loadLibrary("opencv_java");
|
328
|
+
|
329
|
+
Log.d("tem_match","Library_end");
|
330
|
+
|
331
|
+
}catch(Exception e){
|
332
|
+
|
333
|
+
Log.d("tem_match","Library_error");
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
Log.d("inFile","inFile="+inFile+" templateFile="+templateFile+ " outFile="+outFile);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
new MatchingDemo().run(inFile,templateFile,outFile,Imgproc.TM_CCOEFF);
|
342
|
+
|
343
|
+
Log.d("match","new_end");
|
344
|
+
|
345
|
+
Log.d("match","run_end");
|
346
|
+
|
347
|
+
}
|
348
|
+
|
331
349
|
}
|
332
350
|
|
351
|
+
|
352
|
+
|
333
353
|
```
|
334
354
|
|
335
355
|
|
336
356
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
357
|
+
MachingDemo.java
|
358
|
+
|
359
|
+
```MachingDemo.java
|
360
|
+
|
361
|
+
public class MatchingDemo {
|
362
|
+
|
363
|
+
private Mat img;
|
364
|
+
|
365
|
+
private Mat templ;
|
366
|
+
|
367
|
+
private Mat result;
|
368
|
+
|
369
|
+
public MatchingDemo() {
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
public void run(String inFile, String templateFile, String outFile, int match_method) {
|
378
|
+
|
379
|
+
System.out.println("\nRunning Template Matching");
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
Mat img = Highgui.imread(inFile);
|
386
|
+
|
387
|
+
Mat templ = Highgui.imread(templateFile);
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
//結果を作成
|
394
|
+
|
395
|
+
int result_cols = img.cols() - templ.cols() + 1;
|
396
|
+
|
397
|
+
int result_rows = img.rows() - templ.rows() + 1;
|
398
|
+
|
399
|
+
result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
// / Do the Matching and Normalize
|
404
|
+
|
405
|
+
Imgproc.matchTemplate(img, templ, result, match_method);
|
406
|
+
|
407
|
+
//エラー
|
408
|
+
|
409
|
+
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
//閾値が最も高いものを選ぶ
|
414
|
+
|
415
|
+
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
|
416
|
+
|
417
|
+
//マッチング時の最大値と最小値を返す
|
418
|
+
|
419
|
+
Point matchLoc;
|
420
|
+
|
421
|
+
// Point matchLoc = new Point();
|
422
|
+
|
423
|
+
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
|
424
|
+
|
425
|
+
matchLoc = mmr.minLoc;
|
426
|
+
|
427
|
+
} else {
|
428
|
+
|
429
|
+
matchLoc = mmr.maxLoc;
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
//マッチしたところを囲む
|
436
|
+
|
437
|
+
Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
|
438
|
+
|
439
|
+
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
// 結果を保存
|
444
|
+
|
445
|
+
System.out.println("Writing "+ outFile);
|
446
|
+
|
447
|
+
Highgui.imwrite(outFile, img);
|
448
|
+
|
449
|
+
|
364
450
|
|
365
451
|
|
366
452
|
|
@@ -368,124 +454,12 @@
|
|
368
454
|
|
369
455
|
}
|
370
456
|
|
457
|
+
|
458
|
+
|
371
459
|
```
|
372
460
|
|
373
461
|
|
374
462
|
|
375
|
-
```MachingDemo.java
|
376
|
-
|
377
|
-
public class MatchingDemo {
|
378
|
-
|
379
|
-
private Mat img;
|
380
|
-
|
381
|
-
private Mat templ;
|
382
|
-
|
383
|
-
private Mat result;
|
384
|
-
|
385
|
-
public MatchingDemo() {
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
}
|
392
|
-
|
393
|
-
public void run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method) {
|
394
|
-
|
395
|
-
// public Mat run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method) {
|
396
|
-
|
397
|
-
// public Bitmap run(Bitmap inFile, Bitmap templateFile, Bitmap mResult, int match_method) {
|
398
|
-
|
399
|
-
// public void run(String inFile, String templateFile, String outFile, int match_method) {
|
400
|
-
|
401
|
-
System.out.println("\nRunning Template Matching");
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
img = new Mat(inFile.getHeight(), inFile.getWidth(), CvType.CV_8UC1);
|
406
|
-
|
407
|
-
templ = new Mat(templateFile.getHeight(), templateFile.getWidth(), CvType.CV_8UC1);
|
408
|
-
|
409
|
-
Utils.bitmapToMat(inFile, img);
|
410
|
-
|
411
|
-
Utils.bitmapToMat(templateFile, templ);
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
// Mat img = Highgui.imread(inFile);
|
416
|
-
|
417
|
-
// Mat templ = Highgui.imread(templateFile);
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
//結果を作成
|
424
|
-
|
425
|
-
int result_cols = img.cols() - templ.cols() + 1;
|
426
|
-
|
427
|
-
int result_rows = img.rows() - templ.rows() + 1;
|
428
|
-
|
429
|
-
result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
// / Do the Matching and Normalize
|
434
|
-
|
435
|
-
Imgproc.matchTemplate(img, templ, result, match_method);
|
436
|
-
|
437
|
-
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
//閾値が最も高いものを選ぶ
|
442
|
-
|
443
|
-
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
|
444
|
-
|
445
|
-
//マッチング時の最大値と最小値を返す
|
446
|
-
|
447
|
-
Point matchLoc;
|
448
|
-
|
449
|
-
// Point matchLoc = new Point();
|
450
|
-
|
451
|
-
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
|
452
|
-
|
453
|
-
matchLoc = mmr.minLoc;
|
454
|
-
|
455
|
-
} else {
|
456
|
-
|
457
|
-
matchLoc = mmr.maxLoc;
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
//マッチしたところを囲む
|
464
|
-
|
465
|
-
Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
|
466
|
-
|
467
|
-
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
// 結果を保存
|
472
|
-
|
473
|
-
System.out.println("Writing "+ outFile);
|
474
|
-
|
475
|
-
Highgui.imwrite(outFile, img);
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
}
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
```
|
486
|
-
|
487
|
-
|
488
|
-
|
489
463
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
490
464
|
|
491
465
|
Androidstudio2.2.1
|
2
コードの微修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,7 +118,7 @@
|
|
118
118
|
|
119
119
|
Utils.bitmapToMat(temp,mtemp);
|
120
120
|
|
121
|
-
imwrite("TempImg.bmp",mtemp);
|
121
|
+
Highgui.imwrite("TempImg.bmp",mtemp);
|
122
122
|
|
123
123
|
|
124
124
|
|
@@ -254,7 +254,7 @@
|
|
254
254
|
|
255
255
|
//変更点2
|
256
256
|
|
257
|
-
imwrite("dst.bmp",mOutputFrame);
|
257
|
+
Highgui.imwrite("dst.bmp",mOutputFrame);
|
258
258
|
|
259
259
|
//SimpleDateFormat format = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss'.bmp'", Locale.getDefault());
|
260
260
|
|
1
コードを現在のものに更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
```MainActivity.java
|
20
20
|
|
21
|
-
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
|
21
|
+
ppublic class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
|
22
22
|
|
23
23
|
|
24
24
|
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
Bitmap dst;
|
38
38
|
|
39
|
-
|
39
|
+
Mat mtemp;
|
40
40
|
|
41
41
|
|
42
42
|
|
@@ -110,10 +110,26 @@
|
|
110
110
|
|
111
111
|
javacameraview.setCvCameraViewListener(this);
|
112
112
|
|
113
|
+
|
114
|
+
|
113
|
-
//画像をbitmapに変換
|
115
|
+
//画像をbitmapに変換 *変更点1
|
114
116
|
|
115
117
|
temp = BitmapFactory.decodeResource( getResources(),R.drawable.manzu1);
|
116
118
|
|
119
|
+
Utils.bitmapToMat(temp,mtemp);
|
120
|
+
|
121
|
+
imwrite("TempImg.bmp",mtemp);
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
117
133
|
}
|
118
134
|
|
119
135
|
|
@@ -224,17 +240,21 @@
|
|
224
240
|
|
225
241
|
//(Mat型をbitmap型に変換
|
226
242
|
|
227
|
-
dst = Bitmap.createBitmap(mOutputFrame.width(), mOutputFrame.height(), Bitmap.Config.ARGB_8888);
|
243
|
+
// dst = Bitmap.createBitmap(mOutputFrame.width(), mOutputFrame.height(), Bitmap.Config.ARGB_8888);
|
228
|
-
|
244
|
+
|
229
|
-
Utils.matToBitmap(mOutputFrame, dst);
|
245
|
+
// Utils.matToBitmap(mOutputFrame, dst);
|
230
|
-
|
246
|
+
|
231
|
-
Log.d("Mat-Bitmap","完了");
|
247
|
+
// Log.d("Mat-Bitmap","完了");
|
232
|
-
|
248
|
+
|
233
|
-
Log.d("dst","1"+this.dst);
|
249
|
+
// Log.d("dst","1"+this.dst);
|
234
|
-
|
250
|
+
|
235
|
-
Log.d("temp","2"+this.temp);
|
251
|
+
// Log.d("temp","2"+this.temp);
|
252
|
+
|
253
|
+
|
254
|
+
|
236
|
-
|
255
|
+
//変更点2
|
256
|
+
|
237
|
-
|
257
|
+
imwrite("dst.bmp",mOutputFrame);
|
238
258
|
|
239
259
|
//SimpleDateFormat format = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss'.bmp'", Locale.getDefault());
|
240
260
|
|
@@ -242,9 +262,13 @@
|
|
242
262
|
|
243
263
|
|
244
264
|
|
245
|
-
|
265
|
+
|
246
|
-
|
266
|
+
|
247
|
-
|
267
|
+
TemplateMatching.main(dst, temp, "C:/Users/ide/AndroidStudioProjects/OpencvCamera/app/src/main/res/drawable/outfile/output.bmp");
|
268
|
+
|
269
|
+
// TemplateMatching.main("dst.bmp","TempImg.bmp","C:/Users/ide/AndroidStudioProjects/OpencvCamera/app/src/main/res/drawable/outfile/output.bmp");
|
270
|
+
|
271
|
+
|
248
272
|
|
249
273
|
touId = 2;
|
250
274
|
|
@@ -320,14 +344,14 @@
|
|
320
344
|
|
321
345
|
// public static Bitmap main(Bitmap dst, Bitmap temp, Bitmap mResult) {
|
322
346
|
|
347
|
+
// public static void main(String[] args) {
|
348
|
+
|
323
349
|
Log.d("tem_match","Library_start");
|
324
350
|
|
325
351
|
try{
|
326
352
|
|
327
353
|
System.loadLibrary("opencv_java");
|
328
354
|
|
329
|
-
//System.loadLibrary("openCVLibrary2411");
|
330
|
-
|
331
355
|
Log.d("tem_match","Library_end");
|
332
356
|
|
333
357
|
}catch(Exception e){
|
@@ -336,25 +360,13 @@
|
|
336
360
|
|
337
361
|
}
|
338
362
|
|
339
|
-
// new MatchingDemo().run(args[0], args[1], args[2], Imgproc.TM_CCOEFF);
|
340
|
-
|
341
|
-
MatchingDemo match = new MatchingDemo();
|
342
|
-
|
343
|
-
Log.d("match","new_end");
|
344
|
-
|
345
|
-
|
363
|
+
new MatchingDemo().run(dst, temp, outFile, Imgproc.TM_CCOEFF);
|
346
|
-
|
347
|
-
|
364
|
+
|
348
|
-
|
349
|
-
|
365
|
+
|
350
|
-
|
351
|
-
|
366
|
+
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
// return img;
|
356
|
-
|
357
|
-
}
|
367
|
+
}
|
368
|
+
|
369
|
+
}
|
358
370
|
|
359
371
|
```
|
360
372
|
|
@@ -370,15 +382,23 @@
|
|
370
382
|
|
371
383
|
private Mat result;
|
372
384
|
|
373
|
-
public MatchingDemo(){
|
385
|
+
public MatchingDemo() {
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
379
|
-
}
|
391
|
+
}
|
380
|
-
|
392
|
+
|
381
|
-
public void run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method) {
|
393
|
+
public void run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method) {
|
394
|
+
|
395
|
+
// public Mat run(Bitmap inFile, Bitmap templateFile, String outFile, int match_method) {
|
396
|
+
|
397
|
+
// public Bitmap run(Bitmap inFile, Bitmap templateFile, Bitmap mResult, int match_method) {
|
398
|
+
|
399
|
+
// public void run(String inFile, String templateFile, String outFile, int match_method) {
|
400
|
+
|
401
|
+
System.out.println("\nRunning Template Matching");
|
382
402
|
|
383
403
|
|
384
404
|
|
@@ -392,6 +412,14 @@
|
|
392
412
|
|
393
413
|
|
394
414
|
|
415
|
+
// Mat img = Highgui.imread(inFile);
|
416
|
+
|
417
|
+
// Mat templ = Highgui.imread(templateFile);
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
395
423
|
//結果を作成
|
396
424
|
|
397
425
|
int result_cols = img.cols() - templ.cols() + 1;
|
@@ -418,6 +446,8 @@
|
|
418
446
|
|
419
447
|
Point matchLoc;
|
420
448
|
|
449
|
+
// Point matchLoc = new Point();
|
450
|
+
|
421
451
|
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
|
422
452
|
|
423
453
|
matchLoc = mmr.minLoc;
|
@@ -446,8 +476,6 @@
|
|
446
476
|
|
447
477
|
|
448
478
|
|
449
|
-
|
450
|
-
|
451
479
|
}
|
452
480
|
|
453
481
|
}
|