opencv模板查找android,OpenCV in Android matchTemplate Certainty

I am trying to see if a template bitmap contains in another bitmap 2 bitmaps with each other.

Imagine that the 'fed' image is an image where the content consists of a list with some advertisement banners. The template is one of these advertisements.

I am trying to detect if the template advertisement comes up. I've written the following function:

fun findImages(image: Bitmap, template: Bitmap): Bitmap{

var imageMat = bitmapToMat(image)

var template = bitmapToMat(template)

Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_RGB2GRAY)

Imgproc.cvtColor(template, template, Imgproc.COLOR_RGB2GRAY)

val result_cols: Int = imageMat.cols() - template.cols() + 1

val result_rows: Int = imageMat.rows() - template.rows() + 1

val result = Mat(result_rows, result_cols, CvType.CV_32FC1)

Imgproc.matchTemplate(imageMat, template, result, Imgproc.TM_CCOEFF_NORMED)

Core.normalize(result, result, 0.0, 1.0, Core.NORM_MINMAX, -1, Mat())

val mmr = Core.minMaxLoc(result)

val matchLoc: Point = mmr.minLoc

Log.w(TAG, "MinLoc: ${mmr.minLoc.x}, ${mmr.minLoc.y}")

Log.w(TAG, "MaxLoc: ${mmr.maxLoc.x}, ${mmr.maxLoc.y}")

Log.w(TAG, "Val Min Max: ${mmr.minVal}, ${mmr.maxVal}")

Imgproc.rectangle(

imageMat, matchLoc, Point(

matchLoc.x + template.cols(),

matchLoc.y + template.rows()

), Scalar(255.0, 255.0, 0.0)

)

val bmp: Bitmap = Bitmap.createBitmap(imageMat.cols(), imageMat.height(), Bitmap.Config.ARGB_8888)

Utils.matToBitmap(imageMat, bmp)

return bmp

}

But I got stuck at the last bit where I am trying to get the results. I've studied a bit around and I should be able to get it from the minLoc because I am using Imgproc.TM_CCOEFF_NORMED but I cannot utilise this to get the 'certainty rate' or whatsoever. Right?

How should I proceed?

This is btw written in Kotlin with this library port

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值