Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A9T9 RPA searchVision

From Leeroopedia
Knowledge Sources
Domains Computer_Vision, Image_Search
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for orchestrating image-search template matching with DPI normalization and engine routing, provided by the Ui.Vision vision search module.

Description

The searchVision function (`src/search_vision.ts`) is the high-level orchestrator for on-screen image search. It takes a vision image filename, captures a screenshot, loads the pattern image from storage (with platform DPI variants for macOS/Linux), routes the search to the appropriate computer-vision engine (WASM for browser scope, native CV for desktop scope), and returns a `FindResult` with normalized coordinates.

Internally, it uses `getPatternImage` (which resolves platform variants via `platformVariantsOf` — e.g. `tab_dpi_96.png` becomes `tab_mac_dpi_192.png` on macOS Retina), captures the screen via `CaptureScreenshotService`, calls `searchImageInExtensionRouted` (browser) or `getNativeCVAPI` (desktop), and normalizes match coordinates for DPI scaling before returning.

Usage

Call `searchVision` when a macro command needs to locate a UI element by template image matching — the core of visual automation (XClick, visualAssert, etc.).

Code Reference

Source Location

  • Repository: A9T9/RPA
  • File: src/search_vision.ts
  • Lines: L65-L514 (searchVision, getPatternImage, platformVariantsOf)

Signature

export function searchVision(args: SearchVisionParams): Promise<SearchVisionResult>

interface SearchVisionParams {
  visionFileName: string,       // Stored pattern image filename
  minSimilarity: number,        // Confidence threshold (0.1-1.0)
  searchArea?: string,           // 'full' or 'rect'
  storedImageRect?: Rect,        // Crop region for search
  command: Command,              // Originating command (for extra options)
  cvScope: 'browser' | 'desktop',
  devicePixelRatio: number,
  captureScreenshotService: CaptureScreenshotService,
  markSelection?: boolean
}

Import

import { searchVision } from '@/search_vision'

I/O Contract

Inputs

Name Type Required Description
visionFileName string Yes Stored pattern image filename
minSimilarity number Yes Confidence threshold (0.1-1.0)
searchArea string No 'full' (default) or 'rect' for crop
cvScope string Yes 'browser' (WASM engine) or 'desktop' (native CV)
devicePixelRatio number Yes DPI scaling factor

Outputs

Name Type Description
result SearchVisionResult FindResult with normalized coordinates (x, y, rect, score) and storedImageRect

Usage Examples

Search for a Pattern Image

import { searchVision } from '@/search_vision'
import { CaptureScreenshotService } from '@/common/capture_screenshot'

const result = await searchVision({
  visionFileName: 'login_button_dpi_96.png',
  minSimilarity: 0.8,
  searchArea: 'full',
  command: { cmd: 'XClick', target: 'login_button_dpi_96.png', value: '', extra: {} },
  cvScope: 'browser',
  devicePixelRatio: 1.0,
  captureScreenshotService: screenshotService
})

if (result.match) {
  console.log(`Found at (${result.match.x}, ${result.match.y}) score=${result.match.score}`)
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment