Implementation:A9T9 RPA searchVision
| 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
- Principle:A9T9_RPA_Pattern_Image_Loading
- Principle:A9T9_RPA_Engine_Selection
- Principle:A9T9_RPA_Coordinate_Return
Requires Environment
- Environment:A9T9_RPA_Chromium_Browser_Environment
- Environment:A9T9_RPA_Firefox_Browser_Environment
- Environment:A9T9_RPA_Desktop_Automation_XModule2