Ask Your Question
0

How to draw a dotted line [c++]

asked 2017-12-09 12:21:27 -0500

kopar gravatar image

Hello all,

I am new here, i would like to ask you is there a way to change the color of the dotted line which i have created below. LineIterator do not take the color argument... I prefer to use yellow instead a defined blue. Thanks in advance for help.

LineIterator line(img, p1, p2, 8);           
for(int i = 0; i < line.count; i++,line++)
    if ( i%5!=0 ) {(*line)[0] = 200;}
edit retag flag offensive close merge delete

Comments

2
supra56 gravatar imagesupra56 ( 2017-12-09 14:04:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-12-09 19:33:22 -0500

sjhalayka gravatar image

updated 2017-12-09 19:45:05 -0500

This code colours the line in yellow. If you find that this code is helpful, please mark this answer as correct! :)

Mat img = imread("sparks.png");

if (img.empty())
{
    cout << "Error loading image file" << endl;
    return -1;
}

Point p1(20, 20);
Point p2(80, 50);

LineIterator it(img, p1, p2, 8);

for (int i = 0; i < it.count; i++, it++)
{
    if (i % 5 != 0)
    {
        // Yellow
        (*it)[0] = 90; // Blue
        (*it)[1] = 210; // Green
        (*it)[2] = 240; // Red
    }
}

imshow("img", img);
waitKey();
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-12-09 12:21:27 -0500

Seen: 840 times

Last updated: Dec 09 '17