Find Color
Find specified colors and their offset colors in device screenshot, supports multi-point color recognition and tolerance matching.
Interface Description
Interface Type
findColorParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| deviceId | string | Yes | Device ID |
| color | string | Yes | Main color (hex format, e.g., "FFFFFF") |
| offsetColor | string | Yes | Offset color group |
| rect | array | No | Search area [x1, y1, x2, y2], default full screen |
| threshold | number | No | Color tolerance (0-1), default 0.9 |
| multiple | boolean | No | Whether to find all matching locations, default false |
| direction | number | No | Search direction 0-3, default 0 |
Return Value
Single Match (multiple = false):
javascript
{
x: 100, // X coordinate of match point
y: 200 // Y coordinate of match point
}Multiple Matches (multiple = true):
javascript
[
{ x: 100, y: 200 },
{ x: 150, y: 250 },
{ x: 200, y: 300 }
]Basic Usage
javascript
// Find single color point
const result = await apiInvoke('findColor', {
deviceId: 'P72578581E07',
color: '000000', // Main color
offsetColor: '10|0|f6f6f6' // Offset color
});
if (result) {
console.log(`Found color point at (${result.x}, ${result.y})`);
}Feature Description
Color Format
Colors use hexadecimal format:
888888- Gray
Offset Color Format
Offset colors for multi-point color matching, format: "x|y|color,x|y|color,..."
Search Direction
| direction | Description |
|---|---|
| 0 | Left to right, top to bottom (default) |
| 1 | Right to left, top to bottom |
| 2 | Left to right, bottom to top |
| 3 | Right to left, bottom to top |
Color Tolerance
threshold parameter controls color matching accuracy:
1.0- Perfect match, no deviation allowed0.9- Allow about 10% color deviation (recommended)0.8- Allow about 20% color deviation0.7- Allow about 30% color deviation
💡 Tip
Multi-point color matching is more accurate than single point. It's recommended to use 3-5 feature points to identify UI elements, effectively avoiding false matches. Offset color coordinates are relative to the main color point, pay attention to relative position when setting.