cv3.draw.line
- cv3.draw.line(img, x0, y0, x1, y1, rel=None, color=None, t=None, line_type=None, copy=False)[source]
Draw a line on an image.
- Parameters:
img (numpy.ndarray) – Input image to draw on.
x0 (int or float) – X-coordinate of the first point.
y0 (int or float) – Y-coordinate of the first point.
x1 (int or float) – X-coordinate of the second point.
y1 (int or float) – Y-coordinate of the second point.
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 line drawn on it.
- Return type:
numpy.ndarray
Note
Relative coordinates are in the range [0, 1] where 0 is the top/left and 1 is the bottom/right of the image.
Example
>>> import cv3 >>> img = cv3.zeros(100, 100, 3) >>> # Draw a line >>> img = cv3.line(img, 10, 10, 90, 90, color='red', t=2) >>> # Draw a line using relative coordinates >>> img = cv3.line(img, 0.2, 0.2, 0.8, 0.8, rel=True, color='blue')