質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,11 +8,62 @@
|
|
8
8
|
最終的に目指しているのは、アクリル板の台の下にwebカメラを置き、台の上に置かれたものの底に幾何学模様を貼り付けて、その位置に映像を上から映し出す作品です。
|
9
9
|
|
10
10
|
テンプレートマッチングで実装出来そうなのですが、参考に出来るようなサンプルプログラムが見つからず、お手上げの状態です。
|
11
|
+
また、テンプレートマッチングだと認識できる位置が、テンプレート画像内での位置になってしまうかと思うのですがいかがでしょうか。。。
|
11
12
|
|
12
|
-
|
13
|
+
現状でのコードを一応貼って置きます。画像によるテンプレートマッチングです。
|
13
14
|
|
15
|
+
一歩でも動き始められるようなヒントでも良いので、どなたか助言を下されば幸いです。
|
16
|
+
|
14
17
|
何卒宜しくお願い致します。
|
15
18
|
|
19
|
+
##現状でのコード
|
20
|
+
```Processing
|
21
|
+
import processing.video.*;
|
22
|
+
import gab.opencv.*;
|
23
|
+
import org.opencv.core.Mat;
|
24
|
+
import org.opencv.core.CvType;
|
25
|
+
import org.opencv.imgproc.Imgproc;
|
26
|
+
import org.opencv.core.Core.MinMaxLocResult;
|
27
|
+
import org.opencv.core.Core;
|
28
|
+
|
29
|
+
//Capture Camera; //本当はこれで読み込むビデオを入力画像として使いたい
|
30
|
+
|
31
|
+
// 入力画像の準備
|
32
|
+
PImage inputImage = loadImage("tiisakusita1.jpg");
|
33
|
+
OpenCV inputCV = new OpenCV(this, inputImage);
|
34
|
+
Mat inputMat = OpenCV.imitate(inputCV.getGray());
|
35
|
+
|
36
|
+
// テンプレート画像の準備
|
37
|
+
PImage templateImage = loadImage("tiisakusita2.jpg");
|
38
|
+
|
39
|
+
OpenCV templateCV = new OpenCV(this, templateImage);
|
40
|
+
Mat templateMat = OpenCV.imitate(templateCV.getGray());
|
41
|
+
|
42
|
+
// 結果格納用の行列の準備
|
43
|
+
int resultCols = inputMat.cols() - templateMat.cols() + 1;
|
44
|
+
int resultRows = inputMat.rows() - templateMat.rows() + 1;
|
45
|
+
Mat resultMat = new Mat(resultRows, resultCols, CvType.CV_32FC1);
|
46
|
+
|
47
|
+
// テンプレートマッチングを実行
|
48
|
+
Imgproc.matchTemplate(inputCV.getColor(), templateCV.getColor(), resultMat, Imgproc.TM_CCOEFF_NORMED);
|
49
|
+
|
50
|
+
// 結果を描画
|
51
|
+
println("OK!");
|
52
|
+
size(400, 300);
|
53
|
+
image(inputImage, 100, 0);
|
54
|
+
image(templateImage, 10, 10,80,80);
|
55
|
+
|
56
|
+
MinMaxLocResult mmlr = Core.minMaxLoc(resultMat);
|
57
|
+
|
58
|
+
if (mmlr.maxVal > 0.1) {
|
59
|
+
println("Val: " + mmlr.maxVal);
|
60
|
+
stroke(255, 0, 0);
|
61
|
+
strokeWeight(3);
|
62
|
+
noFill();
|
63
|
+
rect((int)mmlr.maxLoc.x + 100, (int)mmlr.maxLoc.y, templateMat.cols(), templateMat.rows());
|
64
|
+
}
|
65
|
+
```
|
66
|
+
|
16
|
-
##参考動画
|
67
|
+
###参考動画
|
17
|
-
https://youtu.be/xbvQ2Z2OeRU
|
68
|
+
[1](https://youtu.be/xbvQ2Z2OeRU)
|
18
|
-
https://youtu.be/GgGKUKbdb0s
|
69
|
+
[2](https://youtu.be/GgGKUKbdb0s)
|