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