# Calculate image rotation to correct for camera angle

I make amateur sports videos with multiple cameras. For basketball games, one camera points at the scoreboard. Ultimately, it's in a position requiring the camera to twist up at the scoreboard at a weird angle. When it's time to insert the clock piece into my game video, I have the option using the Lightworks software to rotate it on 3 axes. However I've been trying to eyeball it and I find that at best I can make 3 of the 4 sides of the scoreboard rectangle straight - a fourth is always angled.

Is there a formula I (as a non-mathematician) can use to calculate the correct rotation on each of the X, Y, and Z axes based on some information from the image itself? Specifically I'm thinking of the original angles of the scoreboard in the image.

Using a ruler in paint.net, I measured that the sides were as follows (angles clockwise from vertical):

• Left: 192.23°, 246.57 pixels
• Top: 93.93°, 802.89 pixels
• Right: 186.83°, 261.85 pixels
• Bottom: 95.16°, 824.33 pixels

I don't know the real dimensions of the scoreboard, but I think I can safely assume that it's a rectangle.

Thank you!

• The formula is possible on the base that camera is observing a rectangle with known dimensions... if you don't know them the problem is harder, it would be interesting also for me to know the method for this case.. – Widawensen Feb 1 '17 at 7:37