opencv android模版匹配,在使用openCV的Android中,模板匹配_android_开发99编程知识库...

我正在嘗試使用模板匹配在Android中與照相機輸入匹配。 當我嘗試使用 static 2圖像時,如下所示: 在安卓的OpenCV模板匹配示例中,所有的工作都很好。 但是當我嘗試使用相機拍攝的圖像時,我沒有得到正確的結果。 下面是我編寫的代碼:String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();

Mat img = Highgui.imread(baseDir +"/mediaAppPhotos/img2.png");

Mat templ = Highgui.imread(baseDir+"/mediaAppPhotos/chars.png");

int result_cols = img.cols() - templ.cols() + 1;

int result_rows = img.rows() - templ.rows() + 1;

Mat result = new Mat(result_cols, result_rows, CvType.CV_32FC1);

///Do the Matching and Normalize

Imgproc.matchTemplate(img, templ, result, Imgproc.TM_CCOEFF);

Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1,

new Mat());

///Localizing the best match with minMaxLoc

MinMaxLocResult mmr = Core.minMaxLoc(result);

Point matchLoc;

if (Imgproc.TM_CCOEFF == Imgproc.TM_SQDIFF

|| Imgproc.TM_CCOEFF == Imgproc.TM_SQDIFF_NORMED) {

matchLoc = mmr.minLoc;

} else {

matchLoc = mmr.maxLoc;

}

///Show me what you got

Core.rectangle(

img,

matchLoc,

new Point(matchLoc.x + templ.cols(), matchLoc.y

+ templ.rows()), new Scalar(0, 255, 0));

//Save the visualized detection.

System.out.println("Writing" + baseDir+"/mediaAppPhotos/result.png");

Highgui.imwrite(baseDir +"/mediaAppPhotos/result.png", img);

我想要這樣的模板匹配,當圖像從攝像機捕獲時。 我們感激任何方式的協助。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值