Multiple templateMatching (Feature #2804)


Added by Baptiste Chinon about 12 years ago. Updated over 9 years ago.


Status:Open Start date:2013-02-15
Priority:Normal Due date:
Assignee:Baptiste Chinon % Done:

0%

Category:imgproc, video
Target version:3.0
Difficulty: Pull request:

Description

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.


Associated revisions

Revision 316e6a8f
Added by Alexander Alekhin almost 11 years ago

Merge pull request #2804 from ilya-lavrenov:tapi_perf

History

Updated by Anna Kogan about 12 years ago

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!

  • Priority changed from High to Normal
  • Target version set to 3.0
  • Assignee set to Baptiste Chinon
  • Category set to imgproc, video

Updated by Cosmin Boaca about 11 years ago

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 ?

Updated by Vladislav Vinogradov about 11 years ago

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:

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

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:

void matchTemplate(InputArray image, const vector<Mat>& templs, Point& loc, int& templInd, double threshold, int method);

Updated by Cosmin Boaca about 11 years ago

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.

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4507

Also available in: Atom PDF