Evo template matching counter

From OpenLAIR/OpenSkill · View interactive version

Evo template matching counter is an AI agent skill from the GitHub repository OpenLAIR/OpenSkill. Counts occurrences of template objects (coins, enemies, turtles) in grayscale keyframe images using OpenCV matchTemplate with TM_CCOEFF_NORMED and Non-Maximum Suppression, then aggregates results into a CSV file.

How to use this skill

Skill file

evo-template-matching-counter

Overview

Counts game sprites (coins, enemies, turtles) in grayscale keyframe images using OpenCV template matching with NMS deduplication, outputs results to CSV.

Key Concepts

Functions

`load_template(template_path)`

Loads template image as grayscale. Returns 2D numpy array.

`non_max_suppression(boxes, overlap_thresh=0.3)`

Malisiewicz et al. NMS algorithm. Input: (N,4) array of [x1,y1,x2,y2]. Returns filtered boxes.

`count_objects_in_frame(frame_gray, template_gray, threshold=0.8, nms_overlap=0.3)`

Counts single object type in a frame. Returns integer count.

`count_all_objects_in_frame(frame_path, templates_dict, threshold=0.8, nms_overlap=0.3)`

Counts all object types in one frame. templates_dict maps label->template array. Returns dict of counts.

`generate_results_csv(frame_paths, templates_dict, output_csv, threshold=0.8, nms_overlap=0.3)`

Processes all keyframes and writes CSV with columns: frame_id, coins, enemies, turtles. Returns DataFrame.

Usage

import sys
sys.path.insert(0, '/app/environment/skills/evo-template-matching-counter/scripts')
from counter_utils import load_template, generate_results_csv

# Load templates as grayscale
templates = {
    "coins": load_template('/root/coin.png'),
    "enemies": load_template('/root/enemy.png'),
    "turtles": load_template('/root/turtle.png'),
}

# frame_paths from extraction step
frame_paths = [f'/root/keyframes_{i:03d}.png' for i in range(1, 28)]

# Generate CSV
df = generate_results_csv(frame_paths, templates, '/root/counting_results.csv', threshold=0.8)

Depends On

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.