A cross-platform C++23 library with a platform-neutral public API and runtime-selected backends: - Input: Wayland virtual pointer/keyboard (Hyprland, wlroots), libei via the RemoteDesktop portal (GNOME, KDE), uinput, and Win32 SendInput - Capture: ScreenCast portal + PipeWire, and Win32 GDI - Windows: Hyprland IPC and Win32 enumeration - Monitors via wl_output/xdg-output and EnumDisplayMonitors - Optional OpenCV template matching (alvin::vision) Also adds the `alvin` CLI, Catch2 unit tests, install rules with find_package(Alvin) support, API docs (docs/API.md and the Obsidian vault), and README instructions for both ways of consuming the library. Windows backends are written but not yet compiled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#pragma once
|
|
|
|
// Optional OpenCV integration (link alvin::vision).
|
|
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
#include <opencv2/core.hpp>
|
|
|
|
#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<Frame> fromMat(const cv::Mat& mat);
|
|
Result<cv::Mat> 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<std::optional<Match>> find(const Frame& haystack, const cv::Mat& needle, const MatchOptions& opts = {});
|
|
Result<std::vector<Match>> findAll(const Frame& haystack, const cv::Mat& needle, const MatchOptions& opts = {});
|
|
|
|
} // namespace alvin::vision
|