first, you should look at the c++ tutorial for this ..
i do not have a java sdk around, so you'll have to take a Kotlin answer instead here;)
starting like this:
>>> var tem = Imgcodecs.imread("logo_2.png", 0)
>>> var img = Imgcodecs.imread("multi.png", 0)
>>> var res = Mat()
>>> Imgproc.matchTemplate(img, tem, res, Imgproc.TM_SQDIFF)
>>> var mm = Core.minMaxLoc(res)
now, if we were looking for a single instance, we would be done here, mm.minLoc would be the found position. (or, maxLoc, if TM_ccoefs was used)
for multiple instances, we have to locate the "valleys" (or, "peaks" with ccoefs) in res.
naively, you would traverse the result image, do a 1st order differenciation, and keep the minima/maxima, but that's unpractical in java, so let's try to threshold the result image, until only single points are left, like this
(believe me, there are points in that image, squint real hard ;):
>>> var bin = Mat()
>>> var thresh = mm.minVal*1.05
>>> Imgproc.threshold(res, bin, thresh, 255.0, -1) // invert, since we're looking for minima
>>> Imgcodecs.imwrite("bin.png", bin) // for visualization
true
>>> var idx = Mat()
>>> Core.findNonZero(bin, idx) // get the positions
>>> idx.dump()
[130, 60;
471, 177;
234, 253]
>>> // done xD. now where's my cookie ?
yes, it is possibe, assuming it works for a single image (no rotation/scaling present)
the only difference with multiple instances is, that you can't simply use minMaxLoc() on the result image, but have to use your own non-maximim/minimum suppression.
Could you give me a sample code for it in java?