0

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 ?

Atef
  • 11
  • 3
  • Both your rectangles are in the first quadrant with their sides parallel to the coordinate axes. An the vectors from point 1 to point 3 for rectangles are in the first quadrant too. I.e. their angles are clearly between 0 and 90 degree. I don´t understand why you expect the second angle to bee negative. – Elec1 Feb 16 '23 at 14:08
  • I know but i expect the second angle to be negative weil the input image is rotated with -90 degrees. – Atef Feb 16 '23 at 14:13
  • How can you expect that a vector in the direction of 85 degrees will have an angle of -85 degrees when it is rotated by 90 degrees (plus or minus)? The resulting angle would be 175 or -5 (or +355) degrees. You would get an angle of -85 as the result of mirroring the vector at the X-coordinate axes. – Elec1 Feb 17 '23 at 16:16

0 Answers0