Repository: opencv
Issue: Multiple templateMatching
Labels: auto-transferred,priority: normal,feature,category: imgproc,category: video

Transferred from http://code.opencv.org/issues/2804

```
|| Baptiste Chinon on 2013-02-15 18:12
|| Priority: Normal
|| Affected: None
|| Category: imgproc, video
|| Tracker: Feature
|| Difficulty: 
|| PR: 
|| Platform: None / None
```
## Multiple templateMatching

```
The templateMatching can only work with one template to be compared with a main picture ; it would be great to update this function to provide multiple-template support, in order to increase performances in such a case. Instead of giving a single template as an input, it could be possible to provide an array of template, and a trigger in another argument ; the templateMatching function would stop and return a result once a template is found with an accuracy > trigger provided as an argument.

FFT on the main picture would be performed only once, as a matter of fact performances would be increased approximately by a factor of 2.
```
## History
##### Anna Kogan on 2013-02-18 10:43

```
Hello Baptiste,
Thank you for reporting the issue. If you could implement the feature yourself, a patch or pull request in the GitHub repo: http://opencv.org/opencv-pull-requests-test-results.html would be highly appreciated!
-   Target version set to 3.0
-   Priority changed from High to Normal
-   Assignee set to Baptiste Chinon
-   Category set to imgproc, video
```
##### Cosmin Boaca on 2014-01-31 14:22

```
Hello, 

I would be glad to implement this feature, but i need some help. 
1. It's about TemplateMatching from cv::cuda namespace ?
2. if Answer to 1 is Yes, then how should i handle multiple templates using InputArray parameter and how can i check the accuracy of a match ?
```
##### Vladislav Vinogradov on 2014-02-02 12:58

```
Hello Cosmin,

Your help would be highly appreciated!

In current version, @matchTemplate@ (both CPU and CUDA) returns map of comparison results, which should be passed to @minMaxLoc@:

<pre>
matchTemplate(image, templ, result, method);
minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc);
// final location - minLoc or maxLoc (depending on method)
</pre>

But, if I understand correctly, Baptiste suggests adding new method, which will compare input image with several templates and return the first result with an accuracy > threshold. Something like:

<pre>
void matchTemplate(InputArray image, const vector<Mat>& templs, Point& loc, int& templInd, double threshold, int method);
</pre>
```
##### Cosmin Boaca on 2014-02-06 14:35

```
Hello,

Sorry for my delayed answer, i had some exams this week.
 I can't figure out how to use the existing functions, and not compute the DFT on the main image for every template. If i us the matchTemplate function with one parameter, this would compute the DFT for every template and that would be no optimization. The only solution i have in mind is like this:

I could add some Mat* imageDFT=0 parameter to the matchTemplate function, and if this parameter is not null and have the proper dimensions i can use it as the dft for the main image, otherwise i would compute it.

If you have any better idea i would like to hear it.
```