Reputation: 13
Using the OpenCV for Processing library by Greg Borenstein, I am able to detect a user's face within a webcam stream, and draw a rectangle around it. Here is the portion that draws the rectangle to the screen:
Rectangle[] faces = opencv.detect()
for (int i = 0; i < faces.length; i++)
{
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
As the user moves their face, the rectangle will move accordingly.
I want to draw a line on the screen where one point is set at predefined location and the other is always pinned to the bottom right hand vertex of the rectangle. This way the length and angle of the line will change with respect to the rectangle's location.
One thing I tried was to subtract some values from faces[i].x
and faces[i].y
until I reached the bottom right vertex, but I found that the depth of the face in the webcam made this method not work.
With that, how could I find the above mentioned vertex of the rectangle so that I can properly draw the line?
Upvotes: 1
Views: 786
Reputation: 42174
The x
position of a rectangle gives you its left side. So x+width
gives you its right side.
Similarly, the y
position of a rectangle gives you its top side. So y+height
gives you its bottom side.
float rectRight = faces[i].x + faces[i].width;
float rectBottom = faces[i].y + faces[i].height;
If that's still not what you're looking for, then please post a small example that we can actually run. Use hardcoded values instead of relying on opencv, so we can copy and paste your code and see the problem ourselves.
Upvotes: 0