This should be simple, but I'm not getting it.
Given that a golf ball is 1.68" and a cup is 4.25" (diameter), if I have a photo showing both the ball and the cup, and know the distance from the camera to the ball, then based upon the size of the ball in the image, I should be able to determine scale, or ratio between the actual size of the ball, and it's perceived size. Then I should also be able to determine the distance between the ball and the cup, based upon the difference in size (or ratio) between the golf ball and the cup.
As a programmer, I'll be working in pixels, but can do it in inches (it would just be very, very small, like 0.01). So, for example, if a 1" ball at 10' appears to be 30 pixels across, and the 2" cup appears to be 10 pixels across, then how far is it from the camera (or the ball), assuming a straight line, of course.
This image is not a great example, as the ball and cup are too reversed (although I could use this), but I'd be looking at using images like this, to determine the distance between the ball and cup, based upon relative sizes.
Golf ball and cup distance problem sample image
Or maybe I don't even need to worry about the size of the ball, and just get the distance of the cup based upon the view angle of the cell phone camera, and the ratio of perceived size of the cup to actual size of the cup?
1758563
$\alpha_C\equiv\quad$ the angle subtended by the image of the cup
$\alpha_B\equiv\quad$ the angle subtended by the image of the ball
$D_C\equiv\quad$ the distance from camera to cup
$D_B\equiv\quad$ the distance from camera to ball
$\begin{array}{l|l} \alpha_C=2\tan^{-1}{\frac{4.25/2}{D_C}}& \alpha_B=2\tan^{-1}{\frac{1.68/2}{D_B}}\\ \alpha_C=2\tan^{-1}{\frac{2.125}{D_C}}& \alpha_B=2\tan^{-1}{\frac{.84}{D_B}}\\ \frac{\alpha_C}2=\tan^{-1}{\frac{2.125}{D_C}}& \frac{\alpha_B}2=\tan^{-1}{\frac{.84}{D_B}}\\ \tan{\frac{\alpha_C}2}=\frac{2.125}{D_C}& \tan{\frac{\alpha_B}2}=\frac{.84}{D_B}\\ \cot{\frac{\alpha_C}2}=\frac{D_C}{2.125}& \cot{\frac{\alpha_B}2}=\frac{D_B}{.84}\\ D_C=2.125\cot{\frac{\alpha_C}2}& D_B=.84\cot{\frac{\alpha_B}2} \end{array}$
By the way, it should be noted that, practically speaking, the elevation of the camera and the downward angle at which it points are also factors which should considered for a complete solution for your project. I just thought you should know.