问题描述
我想用模板匹配,我利用code,我发现,做什么,我希望它保持它的位图,并得到位图的回报,这个问题是我不是完全肯定我怎么能得到在矩形绘制。我仅使用Java,没有原生同时创造的Android应用程序。随着使用的OpenCV其中我在新的。我会得到多个匹配,所以我想获得围绕这些点画出矩形,也能够获得这些比赛的位置值。
mFind =新垫(256,192,CvType.CV_8UC4);
输入=新垫(256,192,CvType.CV_8UC4);垫mResult8u =新垫(256,192,CvType.CV_8UC4);mResult =新垫(217,153,CvType.CV_8UC4);Utils.bitmapToMat(BMP2,mFind);
Utils.bitmapToMat(BMP1,输入);
Imgproc.matchTemplate(mFind,输入,mResult,Imgproc.TM_SQDIFF);
BMP3 = Bitmap.createBitmap(mResult.cols(),mResult.rows(),Bitmap.Config.ARGB_8888);
Core.normalize(mResult,mResult8u,0,255,Core.NORM_MINMAX,CvType.CV_8U);
Utils.matToBitmap(mResult8u,BMP3);
iv2.setImageBitmap(BMP3);
查找匹配的 mResult
,搽在输入RECT
使用 Core.rectangle
和写入文件这一点。
// /本地化最好minMaxLoc比赛
MinMaxLocResult MMR = Core.minMaxLoc(mResult);点matchLoc;
如果(match_method == || Imgproc.TM_SQDIFF == match_method Imgproc.TM_SQDIFF_NORMED){
matchLoc = mmr.minLoc;
}其他{
matchLoc = mmr.maxLoc;
}// / 告诉我你得到了什么
Core.rectangle(输入,matchLoc,新点(matchLoc.x + templ.cols()
matchLoc.y + templ.rows()),新的标量(0,255,0));//保存可视化检测。
的System.out.println(写+不过outFile);
Highgui.imwrite(不过outFile,IMG);
I want to use template matching, i am utilizing a code that i found that does what i want where it keeps it in bitmap and get a return of bitmap, the problem is im not entirely sure how i can get to drawing in the rectangles. I am using only java, no native while creating an app for android. With the use of openCV which i am new at. I will get multiple matches so i would like to get drawn rectangles around those point and also be able to obtain a value for the locations of these matches.
mFind=new Mat(256, 192, CvType.CV_8UC4);
Input = new Mat(256, 192, CvType.CV_8UC4);
Mat mResult8u = new Mat(256, 192, CvType.CV_8UC4);
mResult = new Mat(217, 153, CvType.CV_8UC4);
Utils.bitmapToMat(bmp2, mFind);
Utils.bitmapToMat(bmp1, Input);
Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF) ;
bmp3= Bitmap.createBitmap(mResult.cols(), mResult.rows(),Bitmap.Config.ARGB_8888);
Core.normalize(mResult, mResult8u, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);
Utils.matToBitmap(mResult8u, bmp3);
iv2.setImageBitmap(bmp3);
Find the match in your mResult
, paint the rect on the Input
using Core.rectangle
and write this into file.
// / Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(mResult);
Point matchLoc;
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
} else {
matchLoc = mmr.maxLoc;
}
// / Show me what you got
Core.rectangle(Input, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
// Save the visualized detection.
System.out.println("Writing "+ outFile);
Highgui.imwrite(outFile, img);
这篇关于OpenCV的模板匹配绘制矩形围绕比赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!