Vertical dotted line and and text


I am trying to draw the vertical dotted line. If i try to draw horizontal line and rotate it, it rotates the whole image. So how can i rotate only line or text without rotating the whole image.

how do you draw the dotted line?

i dont think its a nice way but i am trying something like this

dotline = x * “.”
and use cvputtext

in C++ you could have used OpenCV’s LineIterator. that thing implements bresenham.

in python, that’s not accessible.

if you just want vertical/horizontal lines, not angled, you don’t even need bresenham.

just set the pixels yourself.

use numba's @njit decorator to compile the python code. or leave it off. the code is simple enough, won’t take long.

a single such draw call takes maybe 20-50 microseconds on my system.

from numba import njit

@njit
def dashed_vertical_line(img, x, y0, y1, color, stroke=5, gap=5):
    stride = stroke + gap
    for y in range(y0, y1):
        if (y % stride) < stroke:
            img[y,x] = color

im = cv.imread(cv.samples.findFile("lena.jpg"))
dashed_vertical_line(im, x=256, y0=64, y1=384, color=(255,0,0))

1 Like