Ask Your Question
0

Number lines in drawing with incrementing values

asked 2018-04-23 06:47:30 -0600

Grillteller gravatar image

Is it possible in OpenCV to number different lines with incrementing numbers when I draw them? I would have tried it with putText but the second argument (the text) seems to have to be a string. Here is some code of what I tried:

// Draw some lines for calculations
vector<Vec4f> lines_1;
lines_1.push_back(Vec4f(2.0, 0.5, 5.0, 2.5));   
lines_1.push_back(Vec4f(0.0, 0.5, 1.0, 2.5));   
lines_1.push_back(Vec4f(5.0, 1.0,5.0, 4.0));    
lines_1.push_back(Vec4f(3.0, 1.0,4.0, 3.0));    
lines_1.push_back(Vec4f(5.0, 5.0,1.0, 5.0));    
lines_1.push_back(Vec4f(4.0, 8.0,8.0, 4.0));    
lines_1.push_back(Vec4f(8.0, 4.0,8.0, 1.0));

vector<Vec4f> lines_2;
lines_2.push_back(Vec4f(20, 20, 40, 40));
lines_2.push_back(Vec4f(40, 40, 60, 40));
lines_2.push_back(Vec4f(55, 35, 45, 45));
lines_2.push_back(Vec4f(60, 30, 45, 30));
lines_2.push_back(Vec4f(60, 20, 50, 20));
lines_2.push_back(Vec4f(60, 10, 40, 30));
lines_2.push_back(Vec4f(40, 30, 40, 10));

int linecounter = 0;

for (size_t i = 0; i < lines_1.size(); i++){

    linecounter++;  // Increment a counter for every line and draw that text near the line.
    putText(img_1, (cv:String?)linecounter, Point2f(lines_1[p1][0], lines_1[p1][1]), 
HersheyFonts::FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 0, 255), 1, 8);

    line(img_1, Point2f(lines_1[p1][0], lines_1[p1][1]), Point2f(lines_1[p1][2], lines_1[p1][3]), Scalar(0, 0, 255), 1, 8, 0);
    line(img_2, Point2f(lines_2[p2][0], lines_2[p2][1]), Point2f(lines_2[p2][2], lines_2[p2][3]), Scalar(0, 0, 255), 1, 8, 0);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-04-23 06:49:13 -0600

berak gravatar image

use:

String txt = format("%d", linenumber); // printf style
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-23 06:47:30 -0600

Seen: 472 times

Last updated: Apr 23 '18