First call to Template Matching is very slow

I’m using the template matching plugin from here:

It works well, but on the first call it performs very slow. For example after I open ImageJ and use template matching for an image and a template, it takes about 4 seconds, and the following calls on different images while not closing ImageJ, take about 0.5 second.
Is there a way to speed up the first call? Maybe I need to let ImageJ initialize the plugin on startup to save some time for the first call?

Edit (clarification):
The subsequent calls are faster than the first, no matter if using the same or different images…

It looks like the command uses JavaCPP, which uses Loader to load the native libraries when first required.

I have also found this to be slow in QuPath, where the Wand tool relies on OpenCV (via JavaCPP). If this is loaded immediately on startup while populating the toolbar, the entire application takes substantially longer to launch - perhaps 5 seconds or more.

The only workaround I know is to call some OpenCV code in a background thread earlier, so that it is likely to already be initialized before the user needs it. Not sure if/how this should be implemented in this specific ImageJ plugin.


@petebankhead is right. In order to access OpenCV libraries, Loader.load() need to be called before running the plugin at the first time.

Maybe you can try running a dummy command to call the plugin in the startup macro script ?