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

在Android应用中,使用OpenCV进行模板匹配时遇到问题。当使用静态图片(static2图像)时,匹配工作正常,但将图片替换为相机捕获的实时图像后,无法得到预期结果。代码中加载了相机拍摄的图片,并进行了模板匹配和归一化操作,但在定位最佳匹配时出现问题。寻求解决在相机输入图像上进行有效模板匹配的方法。
摘要由CSDN通过智能技术生成

我正在尝试使用模板匹配在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);

我想要这样的模板匹配,当图像从摄像机捕获时。 我们感激任何方式的协助。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值