Utils Module

The utils module provides utility functions for coordinate conversion and other common operations used in computer vision and image processing.

Coordinate conversion utilities.

This module provides functions for converting between different coordinate representations commonly used in computer vision and image processing.

Functions:

xywh2xyxy: Convert from (x, y, width, height) to (x0, y0, x1, y1) format. xyxy2xywh: Convert from (x0, y0, x1, y1) to (x, y, width, height) format. ccwh2xyxy: Convert from (center_x, center_y, width, height) to (x0, y0, x1, y1) format. xyxy2ccwh: Convert from (x0, y0, x1, y1) to (center_x, center_y, width, height) format. yyxx2xyxy: Convert from (y0, y1, x0, x1) to (x0, y0, x1, y1) format. rel2abs: Convert relative coordinates to absolute coordinates. abs2rel: Convert absolute coordinates to relative coordinates.

cv3.utils.xywh2xyxy(x0, y0, w, h)[source]

Convert from (x, y, width, height) to (x0, y0, x1, y1) format.

Parameters:
  • x0 (float) – X-coordinate of the top-left corner.

  • y0 (float) – Y-coordinate of the top-left corner.

  • w (float) – Width of the rectangle.

  • h (float) – Height of the rectangle.

Returns:

(x0, y0, x1, y1) coordinates of the rectangle.

Return type:

tuple

cv3.utils.xyxy2xywh(x0, y0, x1, y1)[source]

Convert from (x0, y0, x1, y1) to (x, y, width, height) format.

Parameters:
  • x0 (float) – X-coordinate of the top-left corner.

  • y0 (float) – Y-coordinate of the top-left corner.

  • x1 (float) – X-coordinate of the bottom-right corner.

  • y1 (float) – Y-coordinate of the bottom-right corner.

Returns:

(x, y, width, height) representation of the rectangle.

Return type:

tuple

cv3.utils.ccwh2xyxy(xc, yc, w, h)[source]

Convert from (center_x, center_y, width, height) to (x0, y0, x1, y1) format.

Parameters:
  • xc (float) – X-coordinate of the center.

  • yc (float) – Y-coordinate of the center.

  • w (float) – Width of the rectangle.

  • h (float) – Height of the rectangle.

Returns:

(x0, y0, x1, y1) coordinates of the rectangle.

Return type:

tuple

cv3.utils.xyxy2ccwh(x0, y0, x1, y1)[source]

Convert from (x0, y0, x1, y1) to (center_x, center_y, width, height) format.

Parameters:
  • x0 (float) – X-coordinate of the top-left corner.

  • y0 (float) – Y-coordinate of the top-left corner.

  • x1 (float) – X-coordinate of the bottom-right corner.

  • y1 (float) – Y-coordinate of the bottom-right corner.

Returns:

(center_x, center_y, width, height) representation of the rectangle.

Return type:

tuple

cv3.utils.yyxx2xyxy(y0, y1, x0, x1)[source]

Convert from (y0, y1, x0, x1) to (x0, y0, x1, y1) format.

Parameters:
  • y0 (float) – First y-coordinate.

  • y1 (float) – Second y-coordinate.

  • x0 (float) – First x-coordinate.

  • x1 (float) – Second x-coordinate.

Returns:

(x0, y0, x1, y1) coordinates.

Return type:

tuple

cv3.utils.rel2abs(*coords, width, height)[source]

Convert relative coordinates to absolute coordinates.

Parameters:
  • *coords – Iterable of coordinates in the form (x0, y0, x1, y1, …, xn, yn).

  • width (int) – Width of the image or reference frame.

  • height (int) – Height of the image or reference frame.

Yields:

int – Absolute coordinates rounded to integers.

Raises:

AssertionError – If the number of coordinates is not even.

cv3.utils.abs2rel(*coords, width, height)[source]

Convert absolute coordinates to relative coordinates.

Parameters:
  • *coords – Iterable of coordinates in the form (x0, y0, x1, y1, …, xn, yn).

  • width (int) – Width of the image or reference frame.

  • height (int) – Height of the image or reference frame.

Yields:

float – Relative coordinates in the range [0, 1].

Raises:

AssertionError – If the number of coordinates is not even.

xywh2xyxy(x0, y0, w, h)

Convert from (x, y, width, height) to (x0, y0, x1, y1) format.

xyxy2xywh(x0, y0, x1, y1)

Convert from (x0, y0, x1, y1) to (x, y, width, height) format.

ccwh2xyxy(xc, yc, w, h)

Convert from (center_x, center_y, width, height) to (x0, y0, x1, y1) format.

xyxy2ccwh(x0, y0, x1, y1)

Convert from (x0, y0, x1, y1) to (center_x, center_y, width, height) format.

yyxx2xyxy(y0, y1, x0, x1)

Convert from (y0, y1, x0, x1) to (x0, y0, x1, y1) format.

rel2abs(*coords, width, height)

Convert relative coordinates to absolute coordinates.

abs2rel(*coords, width, height)

Convert absolute coordinates to relative coordinates.