# Finding point height on a cup using OpenCV

Suppose that I want to find the 3D position of a cup with its rotation, with image input like this (this cup can be rotated to point in any direction):

Given that I have a bunch of 2D points specifying the top circle and bottom circle like the following image. (Let's assume that these points are given by a person drawing the lines around the cup, so it won't be very accurate. Ellipse fitting or SolvePnP might be needed to recover a good approximation. And the bottom circle is not a complete circle, it's just part of a circle. Sometimes the top part will be occluded as well so we cannot rely that there will be a complete circle)

I also know the physical radius of the top and bottom circle, and the distance between them by using a ruler to measure them beforehand.

I want to find the complete 2 circle like following image (I think I need to find the position of the cup and its up direction before I could project the complete circles):

Let's say that my ultimate goal is to be able to find the closest 2D top point and closest 2D bottom point, given a 2D point on the side of the cup, like the following image:

A point can also be inside of the cup, like so:

Let's define distance(a, b) as a function that find euclidean distance from point a and point b in pixel units.

From that I would be able to calculate the distance(side point, bottom point) / distance(top point, bottom point) which will be a scale number from 0 to 1, if I multiply this number to the physical height of the cup measured by the ruler, then I will know how high the point is from the bottom of the cup in metric unit.

What is the method I can use to find the corresponding top and bottom point given point on the side, so that I can finally find out the height of the point from the bottom of the cup?

I'm thinking of using PnP to solve this but my points do not have correct IDs associated with them. And I don't want to know the exact rotation of the cup, I only want to know the up direction of the cup. I also think that fitting the ellipse might help somewhat, but maybe it's not the best because the circle is not complete. If you have any suggestions, please tell me how to obtain the point height from the bottom of the cup.

• "...find the 3D position of a cup with its rotation..." This is only possible if you keep ceertain conditions fixed from a monocular input. Can you please clarify what the output be exactly? (e.g. $x,y,z,\theta$? Or are you simply after the orientation of the paper cup?) – A_A Jan 13 at 12:07
• My final goal is to determine how high the point is from the bottom of the cup. Finding the position is simply an intermediate goal I think will help me to project the ellipse and find the top and bottom point. – off99555 Jan 13 at 12:09
• Can you please edit your question in such a way that it first asks exactly what you need to know (with illustrative drawings etc) adding later what you have done or what you think should be done to get there? Getting the "height" of the paper cup is much more straightforward than all this fitting. – A_A Jan 13 at 12:52
• If you said it's straight forward, how exactly you can do it? Given the real-world measurement of the cup only. I'm not asking for the height of the cup, I'm asking for the height up to the middle point. – off99555 Jan 13 at 15:05