Ask Your Question

How to plot dotted line using OpenCV?

asked 2013-04-06 10:07:24 -0600

heartfly gravatar image

There is 'line' function, but the parameter of lineType has only 3 value, that is 8, 4 and CV_AA. All these plot solid lines. So how can I plot dotted line using OpenCV directly?

Thank you!


Draws a line segment connecting two points. C++: void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-04-06 10:44:03 -0600

berak gravatar image

unfortunately, you can't do it directly, opencv only has solid lines for drawing

if you really need a dotted or stippled line, try something like this:

cv::Mat img = cv::imread("herring.jpeg",1); // bgr image
Point p1(20,20);                            // start & end points 
Point p2(80,50);
LineIterator it(img, p1, p2, 8);            // get a line iterator
for(int i = 0; i < it.count; i++,it++)
    if ( i%5!=0 ) {(*it)[0] = 200;}         // every 5'th pixel gets dropped, blue stipple line
edit flag offensive delete link more

Question Tools


Asked: 2013-04-06 10:07:24 -0600

Seen: 26,513 times

Last updated: Apr 06 '13