TL;DR: Given 4 points on a two dimentional plane, representing a reclangle seen from an unknown perspective, can we deduce the width / height ratio of the rectangle ?
Details:
From a picture, and some opencv work (canny, hough lines, bucketing to tell appart "lines" and "columns", choosing interesting lines, math to deduce lines intersections), I get this:

From this step, it's easy to warp it to a "from the top" view, using opencv getPerspectiveTransform and wrapPerspective to "remove" the perspective, being on the top of the rectangle.
My goal now is to keep the aspect ratio of it, as I loose it while doing my actual warping, because I don't know the ratio it should have.
For this I have to give to getPerspectiveTransform the 4 destination points where I want my 4 found red points to be after warping, not just 4 random points like (0, 0), (0, 100), (100, 100), (100, 0) leading to a deformation if my 4 red points are not a square.
So is there a known way to compute the width/height ratio, or even better the size, of this "seen thrue a perspective rectangle" ?
For the record and the curious, work-in-progress is here: https://github.com/JulienPalard/grid-finder
Yes, here's a pen and pencil method: Find the points $P,Q$ where "parallel" sides interset. The line through $P,Q$ is the "horizon" of the plane containing the rect. Find $R$ such that $\angle QRP=90^\circ$ and $RP=RQ$. Then the parallel to $PQ$ through $R$ intersects your pairs of "parallels" $AB,CD$ resp. $BC,AD$ in points with distance proportional to the rectangle side lengths.