ImageLocator / Screen¶
Image-based element finding and full-screen operations. Requires pip install dolphin-desktop[vision].
ImageLocator¶
ImageLocator
¶
Locate a template image on screen using OpenCV template matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str | Path
|
Path to the template PNG/BMP/JPG image. |
required |
threshold
|
float
|
Minimum match confidence (0-1, default 0.85). |
0.85
|
scales
|
list[float] | None
|
List of scale factors to try during multi-scale matching
(e.g. |
None
|
region
|
tuple[int, int, int, int] | None
|
Default bounding box |
None
|
Source code in src\dolphin_desktop\_image.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
find
¶
Return (cx, cy) of the best template match, or None.
Source code in src\dolphin_desktop\_image.py
find_with_size
¶
find_with_size(
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int, int, int] | None
Return (cx, cy, template_w, template_h) or None.
Used internally by the failover chain so that _ImageElement
has the correct bounding box.
Source code in src\dolphin_desktop\_image.py
find_all
¶
Return all match centres above threshold.
Source code in src\dolphin_desktop\_image.py
click
¶
Click the template match centre.
Source code in src\dolphin_desktop\_image.py
double_click
¶
Double-click the template match centre.
Source code in src\dolphin_desktop\_image.py
wait_for
¶
wait_for(
timeout: float = 10.0,
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int]
Poll every 0.5 s until the template appears; raise on timeout.
Source code in src\dolphin_desktop\_image.py
exists
¶
Return True if the template is found within timeout seconds.
Source code in src\dolphin_desktop\_image.py
as_element
¶
Find the template and return an _ImageElement proxy, or None.
Source code in src\dolphin_desktop\_image.py
Usage¶
from dolphin_desktop import ImageLocator
btn = ImageLocator("templates/ok_button.png", threshold=0.9)
btn.exists() # bool - found on screen right now
btn.wait_for(timeout=10) # wait until it appears
btn.click()
btn.double_click()
# Find all occurrences
matches = btn.find_all()
for x, y in matches:
print(f"({x}, {y})")
# Find one
match = btn.find()
if match is not None:
x, y = match
print(f"({x}, {y})")
Screen¶
Screen
¶
Static helpers for full-screen capture, colour sampling, and OCR.
Source code in src\dolphin_desktop\_image.py
screenshot
staticmethod
¶
pixel_color
staticmethod
¶
Return the (R, G, B) colour at screen coordinate (x, y).
find_image
staticmethod
¶
find_image(
template: str | Path,
threshold: float = 0.85,
region: tuple[int, int, int, int] | None = None,
) -> tuple[int, int] | None
Convenience wrapper: create an ImageLocator and call find().
Source code in src\dolphin_desktop\_image.py
text
staticmethod
¶
Return OCR text of the screen or region via pytesseract.
find_text
staticmethod
¶
Return the centre (x, y) of the first bounding box containing text, or None.
Source code in src\dolphin_desktop\_image.py
Usage¶
from dolphin_desktop import Screen
# Full screenshot
img = Screen.screenshot()
img.save("screen.png")
# Region screenshot (left, top, right, bottom)
img = Screen.screenshot(region=(0, 0, 800, 600))
# Pixel colour
r, g, b = Screen.pixel_color(100, 200)
# OCR - all visible text
text = Screen.text()
text = Screen.text(region=(0, 50, 1920, 100))
# Find text - returns (cx, cy) of first matching word
point = Screen.find_text("Submit")
if point is not None:
x, y = point
from dolphin_desktop import Mouse
Mouse.click(x, y)
# Shortcut
match = Screen.find_image("templates/btn.png")