Perspective image of a rectangle 
The image above shows a perspective image of a rectangle, taken by a pinhole camera that is pointed to the center of the rectangle (This means that the axis of the pinhole camera is assumed to pass through the center of the viewed rectangle, or equivalently that the line connecting the center of the rectangle and its image is perpendicular to the viewing plane).
If the side length $\overline{AB}$ is known to be $6$ units, can we find the side length $\overline{BC}$ ?
Additionally, assume that in the image $AB$ is not parallel to $CD$ and $BC$ is not parallel to $AD$.
 A: Let $ABCD$ be the ordered vertices of the given quadrilateral, $O$ the intersection point of its diagonals and $V$ the position of the point of view (i.e. the pinhole), which lies on the perpendicular through $O$ to plane $ABCD$. We also know that line $VO$ passes through the centre of a rectangle $A'B'C'D'$ whose vertices lie on the rays opposite to $VA$, $VB$, $VC$, $VD$.
Choose any $A'$ on the ray opposite to $VA$, for instance:
$$
A'=2V-A.
$$
Then it is easy to show that the midpoint $M$ of $A'C'$ lies on line $VO$ only if
$$
C'=V+{1\over k}(V-C),
\quad\text{where}\quad
k={OC\over OA}.
$$
Proof. Point $C'$ lies on line $CO$, hence there exists $t$ such that $C'=V+t(V-C)$. On the other hand $C=O+k(O-A)$, hence:
$$
M={A'+C'\over2}={(3+t)V-A-tC\over2}=
{(3+t)V-t(1+k)O+(tk-1)A\over2}.
$$
But $M$ lies on line $VO$ only if $M=\alpha O+(1-\alpha) V$ for some real number $\alpha$. And this is the case only if $tk-1=0$. Plugging then $t=1/k$ into the expression for $C'$ we obtain the desired result. $\square$
In an analogous way, one can prove that $M$ is also the midpoint of $B'D'$ if:
$$
B'=V + {m (1 + k)\over k(1 + m)} (V - B),\quad 
D'= V + {1 + k\over k(1 + m)}(V-D),\quad 
\text{where}\ 
m={OD\over OB}.
$$
The quadrilateral $A'B'C'D'$ so constructed is a parallelogram, but not necessarily a rectangle. We get a rectangle by imposing a further condition, for instance $A'C'=B'D'$. This gives a quadratic equation in the unknown $z=OV$, which can then be solved: two solutions are possible, on either side of plane $ABCD$.
Once $V$ is found one can compute the sides of rectangle $A'B'C'D'$: a simple proportion will then give you the unknown side of the original rectangle.

EXAMPLE.
Let's take for simplicity $ABCD$ in the $xy$ plane in such a way that $O=(0,0,0)$:
$$
A=(-2, -2, 0),\ 
B=(1, -4, 0),\ 
C=(3, 3, 0),\ 
D=(-1, 4, 0),\ 
V=(0,0,z).
$$
We then have $k=3/2$, $m=1$ and:
$$
A'=(2, 2, 2z),\ 
B'=\left(-{5\over6}, {10\over3}, {11\over6}z\right),\ 
C'=\left(-2, -2, {5\over3}z\right),\ 
D'=\left({5\over6},-{10\over3}, {11\over6}z\right). 
$$
Equation $A'C'=B'D'$ boils down to $z^2=137$, that is $z=\pm\sqrt{137}$. We can then compute:
$$
A'B'={7\over3}\sqrt{5\over2},\quad
B'C'={11\over3}\sqrt{5\over2}.
$$
If the real length of $A'B'$ is $6$, a simple proportion will then give the real length of $B'C'$ as $\displaystyle{66\over7}$.
EDIT.
Tinkering a bit with Mathematica I could find a simple formula for $z=OV$:
$$
z^2={ (1 + k)^2 m^2 OB^2-k^2 (1 + m)^2 OA^2
\over (k - m) (k m-1)}.
$$
Of course if the right hand side turns out to be negative then no real solution exists.
A: I'm not an expert on this, but given it a thought I think the following should be right. I can always delete :-|
Assume your object is centered at the origin, and your camera is always looking to the origin at a distance $r$ and with angles $\varphi$ and $\theta$ (spherical coordinates, ISO 80000-2:2019 convention). For the pinhole of the camera we then have $P_{pin}=(x_{pin}, y_{pin}, z_{pin})$:
$$
x_{pin} = r\sin(\theta)\cos(\varphi)\\
y_{pin} = r\sin(\theta)\sin(\varphi)\\
z_{pin} = r\cos(\theta)
$$
The projection is realized by a vector from the object, through the pinhole, onto a plane perpendicular to the viewing vector. Let's put that plane at distance $f$ behind the camera pinhole. The projection plane point where the origin is projected is then given by $P_{pl}=(x_{pl}, y_{pl}, z_{pl})$:
$$
x_{pl} = (r+f)\sin(\theta)\cos(\varphi)\\
y_{pl} = (r+f)\sin(\theta)\sin(\varphi)\\
z_{pl} = (r+f)\cos(\theta)
$$
So we can regard $P_{pl}$ as the normal on the plane, and for every projection point $P_{pr}$ on the plane the vector dot product (relative to $P_{pl}$) with the normal is zero:
$$
(P_{pl}, P_{pr}-P_{pl})=0
$$
which we can simplify as
$$
(P_{pl}, P_{pr})-(P_{pl}, P_{pl})=(P_{pl}, P_{pr})-(r+f)^2=0
$$
A point on your object $P_o=(x_o,y_o,z_o)$ follows a path to the pinhole as follows:
$$
V(\mu)=P_o+\mu(P_{pin}-P_o), \quad 0 \leq \mu \leq 1
$$
and for a certain $\mu>1$ it hits the projection plane in some $V(\mu)=P_{pr}$. So:
$$
(P_{pl}, P_{pr})-(r+f)^2=0\\
(P_{pl}, P_o+\mu(P_{pin}-P_o))-(r+f)^2=0
$$
Work out a bit:
$$
(P_{pl}, P_o)+\mu(P_{pl}, P_{pin}-P_o)=(r+f)^2\\
\mu=\frac{(r+f)^2-(P_{pl}, P_o)}{(P_{pl}, P_{pin}-P_o)}
$$
We can write:
$$
(P_{pl}, P_{pin}-P_o)=(P_{pl}, P_{pin})-(P_{pl}, P_o)
$$
Because $P_{pl}$ and $P_{pin}$ are the 'same' vector but with different length we get:
$$
(P_{pl}, P_{pin})=r(r+f)
$$
Substitute:
$$
\mu=\frac{(P_{pl}, P_o)-(r+f)^2}{(P_{pl}, P_o)-r(r+f)}
$$
So for every object point (put your rectangle in the xy-plane...), every camera position and focal distance $f$ you can calculate the corresponding 3D projection point $V(\mu)$. From that it is easy to calculate the distances between the projected points.
If you have a projection, and the observation location of the camera, then give the actual rectangle points like $(-h/2,-w/2,0)$, $(-h/2,+w/2,0)$, $(+h/2,-w/2,0)$, $(+h/2,+w/2,0)$ in the xy-plane, then calculate the 4 corresponding projection points $V(\mu)$ according to the above scheme (keep $h$ and $w$ as variables), and then you have a set of 4 projection points expressed in $w$ and $h$. Make them equal to the actual 4 projection points to find the size of the original rectangle.
In fact the 6 variables in the model are $(\theta,\varphi,r,f,w,h)$, whereas you will have 4 projection points. So you need only to know 2 of the 6 at forehand in order to calculate the remaining 4.
