如何在OpenCV中的图像上画一条线? [英] How to draw a line on an image in OpenCV?
本文介绍了如何在OpenCV中的图像上画一条线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一条线的极坐标,如何在OpenCV&中将其绘制在图像上? python?
If I have the polar coordinates of a line, how can I draw it on an image in OpenCV & python?
Line
函数得2分,但绘制仅细分.我想从图像的一条边缘到另一条边缘画一条线.
Line
function takes 2 points, but draws only the segment. I want to draw a line from one edge of the image to other.
推荐答案
仅计算2分即可. opencv的Line可以用例如(-10,-10)表示一个点.
Just calculate for 2 points outside. opencv's Line is fine with e.g. (-10,-10) for a point.
import cv2 # python-opencv
import numpy as np
width, height = 800, 600
x1, y1 = 0, 0
x2, y2 = 200, 400
image = np.ones((height, width)) * 255
line_thickness = 2
cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), thickness=line_thickness)
http://docs.opencv.org /2.4/modules/core/doc/drawing_functions.html#cv2.line
这篇关于如何在OpenCV中的图像上画一条线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文