# Missing the cost function of TM\_CCOEFF\_NORMED with mask for matchTemplate() in API doc

**URL:** <https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481>\
**Category:** C++\
**Tags:** matchtemplate\
**Created:** [November 29, 2021, 10:48pm UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481 "2021-11-29T22:48:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yongqiang\_Li](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/yongqiang_li/32/3886_2.png) [@Yongqiang\_Li](https://forum.opencv.org/u/Yongqiang_Li)\
**Post date:** [November 29, 2021, 10:48pm UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481/1 "2021-11-29T22:48:44Z")

</div>

Hi guys,

When reading [the documentation](https://docs.opencv.org/4.5.4/df/dfb/group __imgproc__ object.html#ga586ebfb0a7fb604b35a23d85391329be) of API matchTemplate of 4.5.4, there misses the cost function of TM\_CCOEFF\_NORMED with mask, as showing below. But this API does support mask when choosing TM\_CCOEFF\_NORMED.

 ![tempsnip](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/9/96bfdd1b844527243823581665dd670e9d8976ba.png)

Is it missing in documentation?  
I am a newbie to template matching. Could someone help to find this cost function?

Thanks in advance.

Regards,  
Yongqiang

---

<div class="post-metadata">

**Author:** ![Tim\_Klein](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/tim_klein/32/3496_2.png) [@Tim\_Klein](https://forum.opencv.org/u/Tim_Klein)\
**Post date:** [November 30, 2021, 5:17am UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481/2 "2021-11-30T05:17:00Z")

</div>

I’ve noticed that omission too, and wondered whether it’s a mistake?

To add to the confusion, [this tutorial](http://docs.opencv.org/4.5.4/de/da9/tutorial_template_matching.html) says “Only two matching methods currently accept a mask: TM\_SQDIFF and TM\_CCORR\_NORMED”, but the documentation seems to contradict that.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 30, 2021, 11:49am UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481/3 "2021-11-30T11:49:42Z")

</div>

my two cents: I find those unwieldy “[world formulae](https://en.wikipedia.org/wiki/Theory_of_everything)” (cram it all in, to hell with structure) a disservice to the reader. half the scribbles in every term encode “run on every pixel”, which is the same for all modes. and none of them indicate how the mask affects the calculation.

very likely an oversight. someone once wrote this, then nobody ever touched it again. prime candidate for some drive-by improvements.

---

<div class="post-metadata">

**Author:** ![Yongqiang\_Li](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/yongqiang_li/32/3886_2.png) [@Yongqiang\_Li](https://forum.opencv.org/u/Yongqiang_Li)\
**Post date:** [November 30, 2021, 5:26pm UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481/4 "2021-11-30T17:26:27Z")

</div>

Yes. I also noticed this tutorial. The API documentation was updated.

---

<div class="post-metadata">

**Author:** ![Yongqiang\_Li](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/yongqiang_li/32/3886_2.png) [@Yongqiang\_Li](https://forum.opencv.org/u/Yongqiang_Li)\
**Post date:** [December 3, 2021, 12:05am UTC](https://forum.opencv.org/t/missing-the-cost-function-of-tm-ccoeff-normed-with-mask-for-matchtemplate-in-api-doc/6481/5 "2021-12-03T00:05:36Z")

</div>

After the second look at the API doc, the masked formula is already covered in the line of TM\_CCOEFF.

My problem is resolved! Thanks for everyone’s comment.
