WindowImageProcessedEventArgs

Represents the event arguments for an image processing trigger, containing the results and transformations required to map detected objects from local to screen coordinates.

AI-first navigation: see AI Computer Vision / Images for image-processing events, capture surfaces, and related OpenCV-style workflows.

Convert a detection result to screen coordinates

WindowImageProcessedEventArgs<TDetectionResult> keeps detections with transforms from the same capture. At EyeAuras 20fd3d4, use that result's conversion rather than manually adding a window corner.

Get the screen position of a detected pixel

Run this in a top-level C# script with the application's OpenCV module available. It captures the primary screen and logs a point without clicking:

csharp
using System.Drawing;
using EyeAuras.OpenCVAuras.Scripting;

{
    var api = GetService<IComputerVisionExperimentalScriptingApi>();
    using var cv = api.ForScreen();
    var processed = cv.PixelSearchRaw(Color.Red);
    if (processed.Detected.Bounds is { } localBounds)
    {
        var screenBounds = processed.ToScreen(localBounds);
        var screenPoint = processed.ToScreenPoint(localBounds);
        Log.Info($"Bounds: {screenBounds}, center: {screenPoint}");
    }
    else
    {
        Log.Info("No match");
    }
}

ToScreen applies WorldToScreen, accounting for image transforms, ROI offset and window position. ToScreenPoint selects the transformed rectangle's center by default; pass another RegionAnchorType explicitly. Do not apply this conversion to already converted simple ImageSearch or PixelSearch results.

Detected is the detection result. Captured is shared mutable capture state, not your snapshot: another trigger or script can update it. Do not dispose its images or hand them to a worker as stable data. Use ProcessPixels(image => image.Clone()) and dispose your clone; see the ownership example. Dispose your own Rx subscription when consuming WhenImageProcessed; an event object does not own its source's lifetime.

Reference snapshot

WinRectangle, WinPoint and their F variants below alias System.Drawing types; SharpRectangle means SharpDX.Rectangle. Check current SDK/XML for your version. Individual matrix field names do not establish transform direction; use the result conversion methods. DPI/capture behavior depends on the target environment.

csharp
/// <summary>
/// Represents the event arguments for an image processing trigger, containing the results
/// and transformations required to map detected objects from local to screen coordinates.
/// </summary>
/// <typeparam name="TDetectionResult">The type of the trigger result, encapsulating details about detected objects.</typeparam>
public sealed record WindowImageProcessedEventArgs<TDetectionResult> where TDetectionResult : ICaptureTriggerDetectionResult
{
    /// <summary>
    /// Gets the transformation matrices used to convert coordinates from the local viewport (the region of the window where the image was captured)
    /// to screen coordinates. This includes scaling, rotation, and offset transformations.
    /// </summary>
    public ViewportTransformationMatrices ViewportTransforms { get; init; }
    
    /// <summary>
    /// Gets the result of the image processing trigger, containing detailed information about detected objects,
    /// such as their locations in local coordinates.
    /// </summary>
    /// <example>
    /// This could be an instance of <see cref="IColorSearchDetectionResult"/>, <see cref="IImageSearchDetectionResult"/>,
    /// <see cref="IMLSearchDetectionResult"/>, or <see cref="ITextSearchDetectionResult"/>, depending on the specific trigger used.
    /// </example>
    public TDetectionResult Detected { get; init; } 
    
    /// <summary>
    /// Gets images which were processed by the trigger. They are not included by default and are NOT thread-safe.
    /// You are responsible for making sure that they will not be updated by any other trigger or script.
    /// This will be changed in the future versions.
    /// </summary>
    public ICaptureTriggerState Captured { get; init; }
    
    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates to convert.</param>
    /// <returns>The rectangle in screen coordinates.</returns>
    public WinRectangle ToScreen(SharpRectangle local)
    {
        var screenRect = local.ToWinRectangle();
        return ToScreen(screenRect);
    }
    
    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates to convert.</param>
    /// <returns>The rectangle in screen coordinates.</returns>
    public WinRectangle ToScreen(WinRectangle local)
    {
        return local.Transform(ViewportTransforms.WorldToScreen);
    }

    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates, allowing for fractional pixel values.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates to convert, with floating-point precision.</param>
    /// <returns>The rectangle in screen coordinates, with floating-point precision.</returns>
    public WinRectangleF ToScreen(WinRectangleF local)
    {
        return local.Transform(ViewportTransforms.WorldToScreen);
    }
    
    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates.</param>
    /// <param name="anchorType">The anchor type specifying which part of the rectangle to align with the screen coordinates. Default is <see cref="RegionAnchorType.Center"/>.</param>
    /// <returns>A point in screen coordinates.</returns>
    public WinPoint ToScreenPoint(SharpRectangle local, RegionAnchorType anchorType = RegionAnchorType.Center)
    {
        var screenRect = ToScreen(local);
        var screenRectF = screenRect.ToRectangleF();
        return screenRectF.ToPointInRegion(anchorType).ToPoint();
    }

    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates.</param>
    /// <param name="anchorType">The anchor type specifying which part of the rectangle to align with the screen coordinates. Default is <see cref="RegionAnchorType.Center"/>.</param>
    /// <returns>A point in screen coordinates.</returns>
    public WinPoint ToScreenPoint(WinRectangle local, RegionAnchorType anchorType = RegionAnchorType.Center)
    {
        var screenRect = ToScreen(local);
        var screenRectF = screenRect.ToRectangleF();
        return screenRectF.ToPointInRegion(anchorType).ToPoint();
    }
     
    /// <summary>
    /// Converts a rectangle from local viewport coordinates to screen coordinates, allowing for fractional pixel values.
    /// </summary>
    /// <param name="local">The rectangle in local viewport coordinates.</param>
    /// <param name="anchorType">The anchor type specifying which part of the rectangle to align with the screen coordinates. Default is <see cref="RegionAnchorType.Center"/>.</param>
    /// <returns>A point in screen coordinates.</returns>
    public WinPointF ToScreenPoint(WinRectangleF local, RegionAnchorType anchorType = RegionAnchorType.Center)
    {
        var screenRectF = ToScreen(local);
        return screenRectF.ToPointInRegion(anchorType);
    }
}