my input is a rotated image. Sometimes is 90 degrees and sometimes is -90 degrees. I am using PaddleOCR to extract the text and detect Boundingboxes.
With PaddleOCR i can detect the coordinates of every boundingboxes.
the first one should be between 70 and 90 degrees :
[1267.0, 182.0], [1300.0, 182.0], [1300.0, 278.0], [1267.0, 278.0]
And the second one should be -90 :
[[184.0, 173.0], [221.0, 173.0], [221.0, 669.0], [184.0, 669.0]]
from paddleocr import PaddleOCR
import math
from PIL import Image
ocr = PaddleOCR(use_angle_cls=True, lang='en')
image_path = 'test.png'
result = ocr.ocr(image_path, cls=True)
for line in result:
#for i in range(len(line)):
x1, y1 = line[0][0][0]
x2, y2 = line[0][0][1]
x3, y3 = line[0][0][2]
x4, y4 = line[0][0][3]
print(f"x1, y1 = {x1}, {y1}")
print(f"x2, y2 = {x2}, {y2}")
print(f"x3, y3 = {x3}, {y3}")
print(f"x4, y4 = {x4}, {y4}")
# Calculate the vector between points 1 and 3
dx = x3 - x1
dy = y3 - y1
# Calculate the angle in degrees, accounting for orientation
angle = math.degrees(math.atan2(dy, dx))
print(f"Angle: {angle} degrees")
With this code the reuslts is 71° and 85°. The value 85° should be negative. Can you help me ?