Interactive Tools

AutoCV ships with a handful of interactive helpers for live tuning and inspection. These tools open GUI windows and are intended for local, manual workflows.

AutoColorAid

class autocv.auto_color_aid.AutoColorAid[source]

Bases: Tk

Tkinter application for sampling colours from AutoCV-captured frames.

Note

Instantiating this class starts the Tk main loop and blocks until the UI is closed.

ColorPicker

class autocv.color_picker.ColorPicker(hwnd: int, master: Tk)[source]

Interactive magnifier that returns pixel samples from a target window.

hwnd

Window handle that supplies frames for sampling.

master

Root Tk instance responsible for lifecycle management.

size

Side length (in pixels) of the magnifier canvas.

snip_surface

Canvas displaying the magnified cursor region.

result

Latest sampled RGB colour and screen coordinate.

prev_state

Cached state of the left mouse button for edge detection.

controller

Capture controller used to retrieve frames.

set_geometry(cursor_pos: tuple[int, int] | None = None) None[source]

Set the position and size of the color picker window.

Parameters:

cursor_pos – Current screen coordinates of the cursor. Defaults to the current cursor position.

create_screen_canvas() None[source]

Create the Tkinter canvas and overlay window for the color picker.

on_tick() None[source]

Update the color picker canvas based on the current cursor position.

draw_cursor_coordinates(img: Image, x: int, y: int) Image[source]

Draw the current cursor coordinates onto the magnified image.

Parameters:
  • img – Magnified image.

  • x – X-coordinate of the cursor.

  • y – Y-coordinate of the cursor.

Returns:

Updated image with cursor coordinates drawn.

Return type:

Image.Image

draw_center_rectangle(cropped_image: ndarray[tuple[int, ...], dtype[uint8]]) None[source]

Draw a center rectangle on the color picker canvas as a visual marker.

The rectangle’s outline color is determined by the inverse of the average color of the cropped region.

Parameters:

cropped_image – Cropped image around the cursor.

handle_button_press(x: int, y: int) None[source]

Handle a mouse click to pick a color from the screen.

The method retrieves the color of the pixel at the given coordinates. If the coordinates are outside the bounds of the captured image, a default error value is stored.

Parameters:
  • x – X-coordinate of the picked pixel.

  • y – Y-coordinate of the picked pixel.

property vision: Vision

Expose the underlying Vision instance for compatibility.

ImagePicker

class autocv.image_picker.ImagePicker(hwnd: int, master: Tk)[source]

Interactive overlay for selecting and capturing a region of a window.

create_screen_canvas() None[source]

Create the canvas and transparent overlay window for region selection.

The method brings the target window to the foreground, creates a full-screen overlay with a semi-transparent canvas, and binds mouse events for region selection.

on_button_press(event: CanvasEvent) None[source]

Handle the left mouse button press to record the starting coordinates of the selection.

Parameters:

event – Tkinter event containing the x and y coordinates.

on_snip_drag(event: CanvasEvent) None[source]

Update the selection rectangle as the mouse is dragged.

Parameters:

event – Tkinter event containing the current mouse coordinates.

take_bounded_screenshot(x1: float, y1: float, x2: float, y2: float) None[source]

Capture a screenshot of the selected region of the window.

A Vision instance is created to capture the current image of the window, and then the image is cropped to the specified region.

Parameters:
  • x1 – Starting x-coordinate of the region.

  • y1 – Starting y-coordinate of the region.

  • x2 – Ending x-coordinate of the region.

  • y2 – Ending y-coordinate of the region.

on_button_release(_: Event[Canvas]) None[source]

Finalize the region selection and capture the screenshot.

Once the left mouse button is released, the selected region is determined from the recorded coordinates, a screenshot is taken, and the overlay window is closed.

ImageFilter

class autocv.image_filter.ImageFilter(image: ndarray[tuple[int, ...], dtype[uint8]])[source]

Applies HSV filtering, Canny edge detection, and morphological operations to an image.

Provides a GUI with trackbars to adjust filter settings in real-time.

update_filter_settings() None[source]

Synchronise the stored settings with the active trackbar positions.

get_filtered_image() ndarray[tuple[int, ...], dtype[uint8]][source]

Apply the current filter settings and return the filtered image.

The method updates the filter settings, applies an HSV filter, performs Canny edge detection, and applies erosion and dilation if specified.

Returns:

Filtered image after applying HSV/Canny and morphology.

property filter_settings: FilterSettings

Expose active filter settings for compatibility with the AutoCV API.