UNPKG

@salama/image-finder

Version:

Advanced template matching tool with OpenCV.js featuring color sensitivity, batch processing, and performance optimization

78 lines (70 loc) 2.94 kB
/** * Template Matcher - Main Entry Point (CommonJS) * Advanced template matching with OpenCV.js */ const MatcherWrapper = require('./MatcherWrapper.js'); /** * Advanced template matching class with comprehensive features */ class TemplateMatcher { /** * Find template matches in a screenshot image (unified method supporting single or multiple templates) * @param {string} screenshotPath Path to the screenshot image * @param {string|Array<string>} templatePathOrPaths Single template path or array of template paths * @param {Object} options Matching options * @returns {Promise<Array>} Array of match results */ static async findMatches(screenshotPath, templatePathOrPaths, options = {}) { return await MatcherWrapper.findMatches(screenshotPath, templatePathOrPaths, options); } /** * Find template matches for multiple templates (batch processing) * @deprecated Use findMatches() instead - it handles both single and multiple templates * @param {string} screenshotPath Path to the screenshot image * @param {Array<string>} templatePaths Array of template image paths * @param {Object} options Batch matching options * @returns {Promise<Array>} Array of match results */ static async findMatchesBatch(screenshotPath, templatePaths, options = {}) { // Redirect to unified method for backward compatibility return await MatcherWrapper.findMatches(screenshotPath, templatePaths, options); } /** * Find template variants automatically * @param {string} templatePath Base template path * @param {boolean} debug Enable debug logging * @returns {Promise<Array<string>>} Array of template paths including variants */ static async findTemplateVariants(templatePath, debug = false) { return await MatcherWrapper.findTemplateVariants(templatePath, debug); } /** * Get all available OpenCV matching methods * @returns {Array<string>} Array of available method names */ static getAvailableMethods() { return MatcherWrapper.getAvailableMethods(); } /** * Get default options object with current defaults * @returns {Object} Default options configuration */ static getDefaultOptions() { return MatcherWrapper.getDefaultOptions(); } /** * Generate unique annotation path with timestamp and random component * @param {string} baseDir Base directory for annotations * @param {string} prefix Filename prefix * @param {string} screenshotPath Original screenshot path for context * @returns {Promise<string>} Unique annotation file path */ static async generateAnnotationPath(baseDir, prefix, screenshotPath) { return await MatcherWrapper.generateAnnotationPath(baseDir, prefix, screenshotPath); } } // CommonJS exports module.exports = TemplateMatcher; module.exports.TemplateMatcher = TemplateMatcher; module.exports.Matcher = TemplateMatcher; module.exports.default = TemplateMatcher;