# Calculating 3D rotation of predefined shape from 2D data ( image )

This topic is 2108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing a piece of software that needs a kind of image recognition( think QR code ) to display 3d objects over the camera feed. The 'code' containing the information needed to display the model is a perfect square, but I need to somehow calculate it's 3d rotation. The data available is a constructed 2d quadrilateral based on the camera feed.

##### Share on other sites

I have never tried it, but it is interesting from mathematical point of view ;)

In 2D image you do not have the z position of the each point.

But, if the model is perfect square, then all edges shall be the same length (say L).

Each point p'=(x',y') on screen is representation of some point p=(x,y,z) in 3D space, that:

x0'=x0/z0

y0'=y0/z0

x1'=x1/z1

y1'=y1/z1

x2'=x2/z2

y2'=y2/z2

x3'=x3/z3

y3'=y3/z3

and you know that borders have

(x0-x1)^2+(y0-y1)^2+(z0-z1)^2=L^2

(x1-x2)^2+(y1-y2)^2+(z1-z2)^2=L^2

(x2-x3)^2+(y2-y3)^2+(z2-z3)^2=L^2

(x0-x3)^2+(y0-y3)^2+(z0-z3)^2=L^2

and across the polygon

(x0-x2)^2+(y0-y2)^2+(z0-z2)^2=2*L^2

(x3-x1)^2+(y3-y1)^2+(z3-z1)^2=2*L^2

I assumed that points are sorted.

So you have 14 equations for 13 unknown variables (x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3, L).

It is more than you need. I would try to solve it with some approximate, iterative method

(Newton or maybe least squares). From 3D model you may get the rotations, but,

you need to know which two points are the reference (e.g.. the square rotated by 90 deg around the center is looks as the same square ).

Edited by mawigator

• 9
• 17
• 10
• 11
• 18