cv3.draw.hline

cv3.draw.hline(img, y, rel=None, color=None, t=None, line_type=None, copy=False)[source]

Draw a horizontal line on an image.

Parameters:
  • img (numpy.ndarray) – Input image to draw on.

  • y (int or float) – Y-coordinate of the horizontal line.

  • rel (bool, optional) – Whether to use relative coordinates. Defaults to None.

  • color – Color of the line (default: opt.COLOR).

  • t – Thickness of the line (default: opt.THICKNESS).

  • line_type – Type of line for drawing (default: opt.LINE_TYPE).

  • copy (bool) – Whether to copy the image before drawing (default: False).

Returns:

Image with the horizontal line drawn on it.

Return type:

numpy.ndarray

Note

Relative coordinates are in the range [0, 1] where 0 is the top and 1 is the bottom of the image.

Example

>>> import cv3
>>> img = cv3.zeros(100, 100, 3)
>>> # Draw a horizontal line in the middle
>>> img = cv3.hline(img, 50, color='red', t=2)
>>> # Draw a horizontal line using relative coordinates
>>> img = cv3.hline(img, 0.75, rel=True, color='blue')