@@ -114,25 +114,33 @@ def rotate_facial_area(
114
114
# Angle in radians
115
115
angle = angle * np .pi / 180
116
116
117
+ height , weight = size
118
+
117
119
# Translate the facial area to the center of the image
118
- x = (facial_area [0 ] + facial_area [2 ]) / 2 - size [ 1 ] / 2
119
- y = (facial_area [1 ] + facial_area [3 ]) / 2 - size [ 0 ] / 2
120
+ x = (facial_area [0 ] + facial_area [2 ]) / 2 - weight / 2
121
+ y = (facial_area [1 ] + facial_area [3 ]) / 2 - height / 2
120
122
121
123
# Rotate the facial area
122
124
x_new = x * np .cos (angle ) + y * direction * np .sin (angle )
123
125
y_new = - x * direction * np .sin (angle ) + y * np .cos (angle )
124
126
125
127
# Translate the facial area back to the original position
126
- x_new = x_new + size [ 1 ] / 2
127
- y_new = y_new + size [ 0 ] / 2
128
+ x_new = x_new + weight / 2
129
+ y_new = y_new + height / 2
128
130
129
- # Calculate the new facial area
131
+ # Calculate projected coordinates after alignment
130
132
x1 = x_new - (facial_area [2 ] - facial_area [0 ]) / 2
131
133
y1 = y_new - (facial_area [3 ] - facial_area [1 ]) / 2
132
134
x2 = x_new + (facial_area [2 ] - facial_area [0 ]) / 2
133
135
y2 = y_new + (facial_area [3 ] - facial_area [1 ]) / 2
134
136
135
- return (int (x1 ), int (y1 ), int (x2 ), int (y2 ))
137
+ # validate projected coordinates are in image's boundaries
138
+ x1 = max (int (x1 ), 0 )
139
+ y1 = max (int (y1 ), 0 )
140
+ x2 = min (int (x2 ), weight )
141
+ y2 = min (int (y2 ), height )
142
+
143
+ return (x1 , y1 , x2 , y2 )
136
144
137
145
138
146
def bbox_pred (boxes , box_deltas ):
0 commit comments