0
$\begingroup$

How can one calculate the height of a rectangle where the bottom part is unknown. The rectangle is in perspective, I know the top part and sides. However not the bottom.

Extra info: it's a picture taken of a paper, due to the angle of the camera the object is in perspective, top part being the furthest away and bottom part outside of the camera closest to you.


Situation like this: I know the green intersections, therefore the width in between and both sides (not the length obvious). enter image description here


Below is how I think it should be done, but it's not precise so I'm looking for people to help me determine if I'm doing something wrong or can improve it.

enter image description here

#Paper size:
Pw=21.02cm
Ph=29,73cm

Calibration constant, number of pixels per cm at 50cm distance:
k = ### pixels/cm = (observed pixels calibrated)/Pw
kdist = 50cm

Q = k * Pw pixels width on the observed paper

Distance to top:
dtop = kdist*Q/Px

Px is the top width in pixels

We define a new point for measurement of the width, and define pixels to be perfect squares.
Py = 0.1 * Px (10% down)

New width for the new point, Py: is being manually measured for now.
Px2 calculated at Py.

Distance to Px2:
d2 = kdist*Q/Px2

Calculate height between top and Py:
h = sqrt(sqr(0.1*Pw)+sqr(dtop-d2))

Ratio between 0.1*Pw and full paper length:
r = Ph/h

Bottom line will be:
Y = r*Py
$\endgroup$
  • $\begingroup$ What height do you mean? A rectangle is two dimensional, and lacks the dimension of height. A rectangle consists of two sets of equal sides, whose pairings parallel and opposite of each other. Perhaps I'm missing something here? $\endgroup$ – alxmke May 4 '14 at 13:19
  • $\begingroup$ Are you attempting to calculate the side based on its perspective, or is it its absolute length? Specify, if you would. $\endgroup$ – alxmke May 4 '14 at 13:21
  • $\begingroup$ Sorry maybe I wasn't specific. I'm trying to calculate the length from the top (green intersections) to the bottom (blue intersections). $\endgroup$ – Jafu May 4 '14 at 13:22
  • $\begingroup$ Is it simply a rectangle, whose side lengths you are given three of, and need to find the remaining side's length? If so, please provide the lengths for each side of which you are aware. $\endgroup$ – alxmke May 4 '14 at 13:32
  • $\begingroup$ I'm only aware of the top width, that is the length between left green to right green intersection. That's all. Then I know the sides too, but not the length of them. And then I'm trying to find where the bottom section is, which is outside the camera view. $\endgroup$ – Jafu May 4 '14 at 13:32
0
$\begingroup$

The problem with using "Calibration constant, number of pixels per cm at 50cm distance" is that not all of the scene is at 50cm depth or distance from the camera.

I think you need to remove the perspective correction first like in this example... http://opencv-code.com/tutorials/automatic-perspective-correction-for-quadrilateral-objects/

Perspective remapping

Your green points would be the red and green ones in this example. Now obviously you want your blue points to be the white and blue in this example, which you don't have because they are outside the image. But if you work out where the left and right edges will coincide with the bottom edge of the image (the last row) you can still perform the perspective correction.

http://i.imgur.com/9T1iBIY.jpg

Now the correction is removed you can map pixels to cm and estimate where the bottom edge will appear.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.