opencv中画直线函数可以很方便的绘制出直线。有颜色、线宽、类型等属性可设置。
介绍下opencv画直线函数原型:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** @brief Draws a line segment connecting two points. The function line draws the line segment between pt1 and pt2 points in the image. The line is clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased lines are drawn using Gaussian filtering. @param img Image. @param pt1 First point of the line segment. @param pt2 Second point of the line segment. @param color Line color. @param thickness Line thickness. @param lineType Type of the line. See #LineTypes. @param shift Number of fractional bits in the point coordinates. */ CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0); |
画直线测试代码:
1 2 3 4 5 6 7 8 |
Mat image(500,500,CV_8UC3); cv::imshow("Image", image); TDraw draw(image); line(image,Point(0, 0), Point(500, 500), ColorBlue); line(image,Point(0, 50), Point(500, 50), ColorBlue, 1, LINE_AA); line(image,Point(0, 150), Point(500, 150), ColorBlue, 1, FILLED); line(image,Point(0, 250), Point(500, 250), ColorBlue, 1, LINE_4); cv::imshow("Image", image); |
opencv画直线测试结果: