gpt4 book ai didi

python - 在 Opencv 中绘制断裂线(点线/虚线)

转载 作者:行者123 更新时间:2023-12-05 06:41:31 25 4
gpt4 key购买 nike

如何在 cv2.line(),cv2.rectangle() 等 OpenCV 绘图函数中添加断线(点线/虚线)?

是否有折线的线型?

最佳答案

如果线是水平的或垂直的,你可以这样做。有点 hacky,但如果您不需要任何花哨的东西,只需几行即可完成工作。

y = 100  # vertical position of the line
thickness = 2 # thickness of the line
x0 = 0 # leftmost part of the line
x1 = img.shape[1] # rightmost part of the line
on_time = 10 # pixels out of period that are solid
period = 20 # period between dashes
colour = (0, 0, 255)
img[
y - thickness // 2:y + thickness // 2,
[x for x in range(x0, x1) if x % period < on_time]
] = colour

关于python - 在 Opencv 中绘制断裂线(点线/虚线),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40319980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com