Detect the angle of a surface in real-time

Mate, you are looking for the decomposeHomographyMat function.

First, compute the camera matrix using a checkerboard pattern (see here).
Then, get the homography matrix using feature matching between the recerence image (at 0°) and the camera image; see this tutorial.
Finally use decomposeHomographyMat to get the translation and the rotations of the camera image.

Simple like that.

See also Demo 4 in this page.

P.S. If you are not bound by a predefined image type (square and triangle), you can use an ArUCo marker to get directly the angle of the image. It might even be more robust (as it has more corners.