#pragma once // Optional OpenCV integration (link alvin::vision). #include #include #include #include #include "alvin/error.hpp" #include "alvin/frame.hpp" namespace alvin::vision { // Zero-copy CV_8UC4 (BGRA) view. The Frame must outlive the Mat. cv::Mat view(const Frame& frame); // Deep copy converted to CV_8UC3 (BGR), the layout most OpenCV code expects. cv::Mat toBgr(const Frame& frame); Result fromMat(const cv::Mat& mat); Result loadImage(const std::filesystem::path& path); // BGR Status saveImage(const Frame& frame, const std::filesystem::path& path); // png/jpg/... struct Match { Rect rect; // in frame pixels double score = 0; // 0..1, higher is better }; struct MatchOptions { double threshold = 0.9; bool grayscale = false; // faster, ignores colour differences int maxResults = 16; // findAll only }; // Normalised cross-correlation template matching. Result> find(const Frame& haystack, const cv::Mat& needle, const MatchOptions& opts = {}); Result> findAll(const Frame& haystack, const cv::Mat& needle, const MatchOptions& opts = {}); } // namespace alvin::vision