# How to fit an ellipse to fingertips ? I want to fit ellipse to all the fingertips on this hand using the detected points.
How should I draw ellipse only at those specific places.

Should I store these points in array and draw an ellipse for closest ones? Or is there any optimal solution to this.

edit retag close merge delete

1

You Can use cv::fitellipse function to do that. Here's an example how to use it:

Write something like:

cv::RotatedRect rect = cv::fitEllipse(yourPoints)

All Information of the Ellipse are then stored in the RotatedRect e.g.: float centerX = rect.center.x; float a = rect.size.width;

However, as far as i know the fitellipse() function is currently bugged meaning that in some cases it fails returning the correct ellipse.

Sort by » oldest newest most voted

After reading the docs and some examples I figured out the way it is supposed to be done.

These are the steps :

1. Collecting the points around which you plan to draw ellipse.
I have done this using a C++ std::vector.
2. Declare a Rotated Rect variable.
3. Initialize this variable using the value returned by cv::fitEllipse method.
4. Next in line is to find the center and size of the Rotated Rect.
5. Then we draw the ellipse .

cv::RotatedRect _Ellipse['value you want'];

_Ellipse[i] = cv::fitEllipse(points_vector);

cv::Point2f center = cv::Point2f(_Ellipse[i].center.x ,_Ellipse[i].center.y );


cv::Size2f size = cv::Size2f(_Ellipse[i].size.width,_Ellipse[i].size.width);

cv::Size2f size = cv::Size2f(_Ellipse[i].size.width,_Ellipse[i].size.height);
cv::RotatedRect ellipse_rect = cv::RotatedRect(center, size, _Ellipse[i].angle);

cv::ellipse(ref_image, ellipse_rect, cv::Scalar(0,0,255), -1, 8);


I am still not completely sure about this because it is drawing a circle instead of ellipse, but this is like the gist of what is to be done. Thanks.

EDIT
I made a silly mistake while defining Size2f (width instead of height) . Now I am getting proper ellipse.

more

Is it close to a circle or is it actually a circle. Its a circle when width = height. Also a set of your input points where the circle appears would be good.

I tried to draw a circle at the same points after detecting fingertip coordinates, and they nearly overlapped.

Can you provide an image including your points and the drawn ellipse?

1

Official site

GitHub

Wiki

Documentation