前提・実現したいこと
processingで、webカメラからの映像を読み取ってテンプレートと比較するテンプレートマッチングを実行しようとしています。
そもそも、カメラの映像を表示するところから躓いています。
発生している問題・エラーメッセージ
"matchTemplate"でエラー Return type for the method is missing
該当のソースコード
import gab.opencv.*; import org.opencv.core.Mat; import org.opencv.core.CvType; import org.opencv.imgproc.Imgproc; import org.opencv.core.Core.MinMaxLocResult; import org.opencv.core.Core; import processing.video.*; // Videoを扱うライブラリをインポート Capture inputImage; // ライブカメラの映像をあつかうCapture型の変数 void setup() { /* 画面サイズ */ size(640, 480); /* 接続されている全てのカメラの名前を取得 */ String[] cams = Capture.list(); /* カメラのキャプチャー */ inputImage = new Capture(this, cams[0]); inputImage.start(); } void draw() { /* カメラの画像を取得 */ if (inputImage.available()) { inputImage.read(); } /* 画像を表示 */ PImage inputImage = loadImage("temp.png"); set(0,0,inputImage); } // nyuuryoku no gazou OpenCV inputCV = new OpenCV(this, inputImage); Mat inputMat = OpenCV.imitate(inputCV.getGray()); // template no gazou PImage templateImage = loadImage("temp2.png", "png"); OpenCV templateCV = new OpenCV(this, templateImage); Mat templateMat = OpenCV.imitate(templateCV.getGray()); // kekka wo kakunou suru basyo int resultCols = inputMat.cols() - templateMat.cols() + 1; int resultRows = inputMat.rows() - templateMat.rows() + 1; Mat resultMat = new Mat(resultRows, resultCols, CvType.CV_32FC1); // templatematching wo jikkou //↓この行 Imgproc.matchTemplate(inputCV.getColor(), templateCV.getColor(), resultMat, Imgproc.TM_CCOEFF_NORMED); // kekka wo byouga //↓この行 image(inputImage, 100, 0); MinMaxLocResult mmlr = Core.minMaxLoc(resultMat); if (mmlr.maxVal > 0.9) { println("Val: " + mmlr.maxVal); stroke(255, 0, 0); strokeWeight(3); noFill(); rect((int)mmlr.maxLoc.x + 100, (int)mmlr.maxLoc.y, templateMat.cols(), templateMat.rows()); }
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー