Ask Your Question

How to fit an ellipse to fingertips ?

asked 2016-08-11 12:42:32 -0500

supertramp-sid gravatar image

image description

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 flag offensive close merge delete



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 =; 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.

Ice_T02 gravatar imageIce_T02 ( 2016-08-12 11:15:46 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-17 13:57:10 -0500

supertramp-sid gravatar image

updated 2016-08-23 08:26:44 -0500

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.

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

edit flag offensive delete link 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.

Ice_T02 gravatar imageIce_T02 ( 2016-08-18 04:39:57 -0500 )edit

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

supertramp-sid gravatar imagesupertramp-sid ( 2016-08-18 06:01:29 -0500 )edit

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

Ice_T02 gravatar imageIce_T02 ( 2016-08-18 06:06:04 -0500 )edit

@Ice_T02 Issue resolved. there was a silly mistake.

supertramp-sid gravatar imagesupertramp-sid ( 2016-08-23 08:27:32 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-08-11 12:42:32 -0500

Seen: 485 times

Last updated: Aug 23 '16