Somashekar
Somashekar

Reputation: 31

How to draw a line between two points in opencv c++

  Point p1(faces[i].x + (eyes[j].x +  eyes[j].width*0.5), faces[i].y + (eyes[j].y + eyes[j].height*0.5));
  Point p2(faces[i].x + (eyes[j].x +  eyes[j].width*0.5), faces[i].y + (eyes[j].y + eyes[j].height*0.5));
  line(frame, p1, p2, Scalar( 255, 255, 0 ), 5, 8, 0);

This is the code I had wrote to draw a line segment between the two points p1 and p2. Actually I am getting the display of points, but no line segment. Can anybody help me!!

Thanks in advance.

Upvotes: 2

Views: 3053

Answers (1)

Marco A.
Marco A.

Reputation: 43662

With the code provided above one can deduce that the two points are located in the same place thus you're not getting any line but rather a point.

Also take a look at the line function: http://docs.opencv.org/modules/core/doc/drawing_functions.html#line

By the way: there's a problem with your indices. If you're trying to link two eyes' centers you should rather do something like

Point p1(faces[0].x + (eyes[0].x +  eyes[0].width*0.5), faces[0].y + (eyes[0].y + eyes[0].height*0.5));
Point p2(faces[0].x + (eyes[1].x +  eyes[1].width*0.5), faces[0].y + (eyes[1].y + eyes[1].height*0.5));

assuming faces[0] points to the coordinates of a squared face, eyes[0] is the first eye on that face and eyes1 is the second eye (and assuming that the following doesn't happen)

enter image description here

Upvotes: 2

Related Questions